I have switched to gradle 3.4-rc-2 with the wrapper, I have added the options to the build.gradle, and I am trying to run the build with the incremental compiler for performance improvements.
However, here is the message I get when gradle compiles the project:
Project:compileJava - is not incremental. Annotation processors are required.
Are Annotation Processors required for incremental compile? I didn’t see anything about that being a requirement in the release notes. Is this a bug, or am I doing something wrong?
Here is the relevant section in my build.gradle:
compileJava {
//enable compilation in a separate daemon process
options.fork = true
This message is actually saying the opposite. Incremental compilation is not possible when annotation processors have been found on the classpath. You must have a dependency which is registering an annotation processor on the classpath.
Quite simply, our incremental compiler implementation is not capable of considering what annotation processors might do. For example, adding a source retention only annotation to a class would normally result in us not recompiling (as it would not affect bytecode) but this annotation might result in an annotation processor creating a class, etc. For that reason, to ensure correctness, we simply disable incremental compilation. This is a known limitation.
So the snippet I gave you before is somewhat misleading. All that means is that one of those jars has an annotation processor. Not that they all contain an annotation processor.
Not exactly. Annotation processors act on your code. Basically, they are like extentions to the Java compiler which can do things like generate code, modify existing classes, etc. They do this by looking for certain annotation in your code, if they find them, they perform some work at compilation time. In this case, log4j2 uses an annotation processor to search for plugin classes annotated with @Plugin. If your code doesn’t contain any log4j plugins you can safely disable this. You can turn off annotation processing completely via a compiler argument. This will also inform Gradle that you do no wish to use annotation processing and should enable incremental compilation.
Hi again mark, thanks for the great info, that makes sense!
Unfortunately things are even stranger now, after I added your tasks.withType argument, I’m getting compile errors like “error: cannot find symbol sun.security.pkcs10.PKCS10”
Without the argument, things compile correctly.
Do you have any idea why the “-proc:none” argument would cause problems for using sun security classes?
3.4 provides a strongly typed way to define which processors to use:
compileTask.options.annotationProcessorPath =...
In your case an empty file collection will do. See the Java plugin documentation for 3.4 for more information.
If you don’t specify that we fall back to using whatever processors are on your compile classpath. That disables both incremental compile and compile avoidance, so it’s really important to declare processors (or the fact you don’t want any) explicitly. We also handle the jvm arguments, like proc:none, but I think the explicit DSL is simpler to use.
I have configured the annotationProcessorPath for my compile task, and I am using some other code provided in this thread by @mark_vieira to inspect the effectiveAnnotationProcessorPath to make sure that only the jars I have added to the annotationProcessorPath are being included. That’s working correctly. When I run the compile, the code provided by Mark correctly shows the jar file that has the annotation processor and no other jars.
However, gradle is also telling me that the compile is not incremental because annotation processors are found:
`:ComBase:Common:compileJava - is not incremental. Annotation processors are present.`
I’m using 3.4-rc-3. My reading of the docs suggests that I’m doing this correctly.
I don’t know if this information is relevant, but in case it is:
The processor jar is the same jar that contains the annotation to be processed. This necessarily places a compile-time dependency on that jar so that we can actually apply the annotation. I have created a separate jar that contains ONLY the annotation, and that jar is on the compile path. The processor jar still has the annotation class. This means the annotation itself will be found twice.
Also, the main code has a compile time dependency on a library that the processor needs at runtime. That library is therefore duplicated in the apt config as well as the compile config.
@mikesnare you are actually using annotation processors, so we can’t do incremental compile.
The original poster did not want to use them (they were just included accidentally through a transitive dependency) and was asking how to get rid of them.
Our incremental compile depends on the class dependencies that are part of the normal Java language specification. Annotation processors can introduce completely new and unexpected relationships, so to be safe we need to disable incremental compile.
We will explore options to improve this in the future. Potentially we can inspect what the processors are doing or maybe we can provide an API for annotation processor authors to tell us what they are doing.