gradle-checker-framework-plugin icon indicating copy to clipboard operation
gradle-checker-framework-plugin copied to clipboard

Not working well with generated source from another processor

Open riyaz opened this issue 7 years ago • 13 comments

Try to use this plugin in my android project where I also use Glide image library.

Glide generates Java source (GlideApp) dynamically which is used in app, however plugin is unable to find that as source, if i don't use checker app complies normally

/Users/xxx/work/code/app/src/main/java/com/yyy/MainActivity.java:113: error: cannot find symbol import com.yyy.GlideApp; ^ symbol: class GlideApp location: package com.yyy

Am I missing something?

riyaz avatar Feb 07 '18 15:02 riyaz

Is that the whole error? Can you provide more details? Maybe this has been tested with Java and Android?

jaredsburrows avatar Feb 27 '18 01:02 jaredsburrows

The problem is that the checker plugin overwrites both the processor path and which processors to use. As a result no other annotation processors (e.g. the one from Glide) will run.

oehme avatar Mar 16 '18 17:03 oehme

@oehme Thanks for the explanation. Should I be appending these on instead of overwriting?

jaredsburrows avatar Mar 16 '18 17:03 jaredsburrows

I think so. But there is a conceptual problem: The plugin sets the -processor option based on the checkers selected in the extension. That will deactivate all other processors. I'm not aware of a way to solve that dilemma using javac's arguments.

Maybe running all checkers is a better default and you could ask users to use -processor themselves if they really want to filter, keeping in mind the effect that has on other processors?

oehme avatar Mar 16 '18 18:03 oehme

@oehme I will try to look into that. I based this plugin on this Checker framework documentation here: https://checkerframework.org/manual/#android-gradle.

jaredsburrows avatar Mar 16 '18 18:03 jaredsburrows

Yeah that document assumes no other annotation processors.

oehme avatar Mar 16 '18 18:03 oehme

I might need to try the better default or update the README.md.

jaredsburrows avatar Mar 16 '18 19:03 jaredsburrows

I just looked at their code base. They don't have any descriptors for auto discovery (intentionally). So what you can do is write a task that generates a file called META-INF/services/javax.annotation.processing.Processor, list the checkers in there and then put that file into a folder and add that folder to the processor path of the compile task. Then Gradle and javac will pick those processors up during discovery without overwriting others.

oehme avatar Mar 16 '18 21:03 oehme

Also while you're changing it - Passing the -processorpath option as a string is deprecated, because we have a DSL method (options.annotationProcessorPath) for it. That option will work properly with up to date checking and caching. The same is true for the bootClasspath.

oehme avatar Mar 17 '18 16:03 oehme

+1 for this. Doesn't work in combination with Lombok

There is another way since Gradle 4.6: use annotationProcessor and testAnnotationProcessor configurations

grv87 avatar Jun 19 '18 16:06 grv87

@grv87 Can you make a PR? @oehme might be able to take a look?

jaredsburrows avatar Nov 21 '18 18:11 jaredsburrows

@jaredsburrows, I've stopped using this plugin, at least for now. IIRC, my code was OK, but checker-framework didn't work for my case. But no warranties. If you are ready to fix any issues that can arise during review, feel free to open PR with my code by yourself.

grv87 avatar May 21 '19 13:05 grv87

I am currently not using this on any projects. I am open to pull requests.

jaredsburrows avatar Jun 05 '19 04:06 jaredsburrows