Ibotta/gradle-aspectj-pipeline-plugin

KAPT incremental annotation processing is broken with the plugin added to the build

kzsolti opened this issue ยท 11 comments

Hi! I've found this plugin after checking out @jdvp's writeup about switching AOP plugins. We're having the exact same issues he had in our project, so I tried out the Ibotta plugin to see if it's a viable replacement for us too. Unfortunately I ran into some issues.

It seems like that KAPT incremental processing breaks when this plugin is added in alongside it. Everything works fine on the first build, but compilation fails at the annotation processing stage after making changes to the code and rerunning the build. I'm getting errors like this for the class that has been changed:

> Task :app:kaptDebugKotlin FAILED
23 actionable tasks: 2 executed, 21 up-to-date
C:\Projects\Android\Samples\ibotta-plugin-sample\app\src\main\java\com\example\aopsample\logic\Controller.java:12: error: cannot find symbol
    private final Counter counter = new Counter();
                  ^
  symbol:   class Counter
  location: class Controller
FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:kaptDebugKotlin'.
> A failure occurred while executing org.jetbrains.kotlin.gradle.internal.KaptExecution
   > java.lang.reflect.InvocationTargetException (no error message)

The error will list any and all other classes from our project referenced in the changed class.

I can't share code from our main project, but I managed to reproduce the issue exactly in a minimal example. You can find the code here: https://github.com/kzsolti/ibotta-plugin-sample

I set up the sample in the same way: added some mixed Java and Kotlin classes that depend on each other, added the AOP plugin as documented, and added KAPT and an annotation processor dependency with incremental processing enabled.

To demonstrate the issue simply build the project, make changes in the Controller or LoggerAspect classes as I marked with comments, and rebuild to trigger the incremental step. It should fail. Removing the Ibotta plugin, or disabling the incremental annotation processing with kapt.incremental.apt=false makes the error go away. The AOP weaving is working without issue otherwise.

@kzsolti Thanks for the report. I'll take a look now and see if I can figure out what's going on. Just a heads up, I might have to reach out to our Gradle counterparts if it's not obvious. They might have a better understanding of why this might be happening. I'll get back to you shortly.

@kzsolti

I was able to reproduce the issue with your example straight away.

In order to diagnose and potentially fix it further, I'd like to reproduce the problem in the sample apps of this project. However, so far, I've been unsuccessful in reproducing the problem. I have created a branch with the changes here: https://github.com/Ibotta/gradle-aspectj-pipeline-plugin/tree/feature/es_broken_kapt_test

You can see the changes relative to the main branch here: https://github.com/Ibotta/gradle-aspectj-pipeline-plugin/compare/feature/es_broken_kapt_test?expand=1

Assuming I set things up the same way you did, I would assume that a change in the JavaAspect class (the log statement) would reproduce the problem. But it doesn't seem to be.

Maybe I missed a step in the setup. Any chance I can get your ๐Ÿ‘€ on this to see what I might be missing?

@eschlenz

I took a look at your branch, tried a few things, but I can't immediately reproduce my issue with it either. It looks like you've added KAPT just like I did, and if I set kapt.verbose=true I can see that the change in JavaAspect triggers the incremental annotation processing step. It's not obvious what the significant difference between our apps is here... I'll dig into this more tomorrow to try and reproduce on your branch.

@eschlenz

So far I'm still unable to break the sample-mixed module that you tried to reproduce with, but I was able to successfully produce the issue by transplanting my sample code into a new module in your project. You can find it here in my fork on the same branch: https://github.com/kzsolti/gradle-aspectj-pipeline-plugin/tree/feature/es_broken_kapt_test/sample-broken-kapt

I took my code, while using the build script from the mixed module. I only changed the configuration in it to match my sample, while respecting the plugins and dependencies, and their version that your project supplies. I hope I got it right. It produces the error just like my earlier sample did, let me know if it helps diagnosing this!

If I have some time later I'll take another swing at making your module break. I'm really curious what the particular difference is that avoids the compilation error there. I thought the source set handling was the obvious answer, but I tried mmoving the kotlin files into the java set and removing the config from the build script, and it didn't seem to make a difference.

@eschlenz update:

I broke it! I figured out how to break your sample module! ๐Ÿ˜ There's no need to muck around with the build script or gradle beyond adding KAPT, all it took was adding a class field to JavaAspect: kzsolti@fae69ad

Now it breaks just like my sample when you modify the class and recompile.

Nice, I can confirm that worked for me as well. Thank you. I'll report back soon.

Whatever the issue is, it's not obvious, at least to me. I'm going to see if I can get some more ๐Ÿ‘€ ๐Ÿง  on this issue. I'll report back.

Still researching this. I've been working with people from Gradle who are giving me some ideas. Probably won't make much more progress before Monday though. Just fyi

@kzsolti

Hey, good news! With the help of Gary @ Gradle we were able to implement a solution to your reported issue. The fix was released as version 1.1.0: here.

I confirmed the fix in a few places, including the sample code you provided. Can you give it a try and report back please? Thanks

Thanks @eschlenz , I can confirm this issue is solved for my samples, and our main project as well! The incremental behavior works fine now.

Glad to hear it! I'll close this issue out.