Gradle + RoboBinding with AspectJ + Lombok are not compatible together

匿名 (未验证) 提交于 2019-12-03 08:59:04

问题:

I want to integrate in Android project on Gradle following libraries:

  • Lombok
  • RoboBinding with AspectJ
  • Dagger

In order to use RoboBinding with AspectJ and android tools 1.1.0 I compiled aspectj-plugin with this fix.

All libraries are using some compile time annotation processing. I found that Lombok isn't compatible with AspectJ. I noticed that annotation processor from RoboBinding is using apt whereas lombok works only with provided (Dagger works with both).

I found also Lombok and AspectJ workaurond for Maven but I don't know if this can be used with Gradle too (if yes I don't know how to do it).

Without Lombok project is compiling and working. Can you help with integrating Lombok and AspectJ with Gradle?

Error:

Note: Start RoboBinding annotations processing... Note: Start RoboBinding annotations processing... Note: Start RoboBinding annotations processing... Note: Start RoboBinding annotations processing... :app:compileDebugAspectJ warning You aren't using a compiler supported by lombok, so lombok will not work and has been disabled. Your processor is: org.aspectj.org.eclipse.jdt.internal.compiler.apt.dispatch.BatchProcessingEnvImpl Lombok supports: sun/apple javac 1.6, ECJ error at model.setOutput(model.getInput());  D:\Projects\BinderExample\app\src\main\java\foo\binderexample\MainActivity.java:32:0::0 The method getInput() is undefined for the type BinderModel Error:Note: Start RoboBinding annotations processing... Note: Start RoboBinding annotations processing... Note: Start RoboBinding annotations processing... Note: Start RoboBinding annotations processing... error at model.setOutput(model.getInput());  D:\Projects\BinderExample\app\src\main\foo\binderexample\MainActivity.java:32:0::0 The method getInput() is undefined for the type BinderModel FAILURE: Build failed with an exception.  * What went wrong: Execution failed for task ':app:compileDebugAspectJ'. > The method getInput() is undefined for the type BinderModel

Module:

@Module(injects = MainActivity.class) public class BinderModule {      @Provides     @Singleton     BinderModel provideBinderModel() {         return new BinderModel();     } }

Model:

@Data @PresentationModel public class BinderModel implements HasPresentationModelChangeSupport {      private final PresentationModelChangeSupport changeSupport = new PresentationModelChangeSupport(this);      private String input;     private String output;      @Override     public PresentationModelChangeSupport getPresentationModelChangeSupport() {         return changeSupport;     } }

Activity:

public class MainActivity extends Activity {      @Inject     BinderModel model;      @Override     protected void onCreate(Bundle savedInstanceState) {         super.onCreate(savedInstanceState);         ObjectGraph.create(new BinderModule()).inject(this);         View view = Binders.inflateAndBind(this, R.layout.activity_main, model);         setContentView(view);         ButterKnife.inject(this);     }      @OnClick(R.id.button)     void onButtonClick() {         model.setOutput(model.getInput());     } }

Layout:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"               xmlns:bind="http://robobinding.org/android"               android:layout_width="match_parent"               android:layout_height="match_parent"               android:orientation="vertical">      <EditText         android:id="@+id/editText"         android:layout_width="match_parent"         android:layout_height="wrap_content"         android:layout_gravity="center_horizontal"         android:inputType="text"         bind:text="${input}"/>      <Button         android:id="@+id/button"         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:layout_gravity="center_horizontal"         android:text="@string/button"/>      <TextView         android:id="@+id/textView"         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:layout_gravity="center_horizontal"         android:textAppearance="?android:attr/textAppearanceLarge"         bind:text="{output}"/>  </LinearLayout>

Gradle script:

buildscript {     repositories {         jcenter()         mavenLocal()     }      dependencies {         classpath 'com.neenbedankt.gradle.plugins:android-apt:1.4'         classpath 'org.robobinding:aspectj-plugin:0.8.3-fix'     } }  apply plugin: 'com.android.application' apply plugin: 'org.robobinding.android-aspectj' apply plugin: 'com.neenbedankt.android-apt'  android {     compileSdkVersion 21     buildToolsVersion "21.1.2"      defaultConfig {         applicationId "foo.binderexample"         minSdkVersion 15         targetSdkVersion 21         versionCode 1         versionName "1.0"     }      buildTypes {         release {             minifyEnabled false             proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'         }     } }  dependencies {     compile fileTree(include: ['*.jar'], dir: 'libs')     compile 'com.android.support:appcompat-v7:22.0.0'      compile 'com.jakewharton:butterknife:6.1.0'      //dagger     compile 'com.squareup.dagger:dagger:1.2.2'     apt 'com.squareup.dagger:dagger-compiler:1.2.2'      //lombok     provided 'org.projectlombok:lombok:1.16.2'     apt 'org.projectlombok:lombok:1.16.2'      //robobinding     compile('org.robobinding:robobinding:0.8.9:with-aop-and-dependencies') {         exclude group: 'com.google.guava', module: 'guava'     }     aspectPath('org.robobinding:robobinding:0.8.9:with-aop-and-dependencies') {         exclude group: 'com.google.guava', module: 'guava'     }     apt 'org.robobinding:codegen:0.8.9' }

回答1:

If you want to know more about the situation of Lombok in combination with AspectJ, please read my other answer and also follow the links there.



易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!