I have my own annotation processor that I would like to use in a custom task rather than the default compileJava task. When I run annotation processing through the default compileJava task, incremental generation “just works”. The setup in build.gradle looks like the following:
dependencies {
annotationProcessor 'com.generators:interfacegenerator:0.0.1'
compileOnly 'com.generators:interfacegenerator:0.0.1'
}
I can update a single source file, and the annotation processing is done only against that file:
> Task :compileJava
Caching disabled for task ':compileJava' because:
Build cache is disabled
Task ':compileJava' is not up-to-date because:
Input property 'stableSources' file C:\blahblah\sourcegeneration\src\main\java\gradledeps\sourcegeneration\OtherClass.java has changed.
Created classpath snapshot for incremental compilation in 0.0 secs.
Class dependency analysis for incremental compilation took 0.005 secs.
Compiling with JDK Java compiler API.
Incremental compilation of 2 classes completed in 0.186 secs.
:compileJava (Thread[Daemon worker Thread 13,5,main]) completed. Took 0.246 secs.
I would like to do the generation only in its own task. The following is my attempt:
task generateSources(type: JavaCompile) {
options.compilerArgs = ['-proc:only']
source = "src/main/java"
classpath = compileJava.classpath
destinationDir = compileJava.destinationDir
options.annotationProcessorPath = compileJava.options.annotationProcessorPath
}
When I run this after changing a single input file, all of the files are re-procoessed.:
..\gradlew.bat --info generateSources
> Task :generateSources
Caching disabled for task ':generateSources' because:
Build cache is disabled
Task ':generateSources' is not up-to-date because:
Input property 'stableSources' file C:\blahblah\sourcegeneration\src\main\java\gradledeps\sourcegeneration\OtherClass.java has changed.
Full recompilation is required because unable to get source-classes mapping relationship from last compilation. Analysis took 0.0 secs.
If anyone could help out with this, I’d greatly appreciate it!
For reference, the code is in this github project: gradledeps/sourcegeneration at master · nestedsoftware/gradledeps · GitHub