Hello,
This is a project I am migrating from ant. The project includes a class AnnotationProcessor.java, which I need to use to generate source code for the same project. I am invoking JavaCompile like so:
task compileAnnotationProcessor (type: JavaCompile) { //first pass compiles AnnotationProcessor.java and puts it in sourceSets.main.java.outputDir
source sourceSets.main.java
classpath = sourceSets.main.compileClasspath
destinationDir sourceSets.main.java.outputDir
sourceCompatibility = '1.8'
targetCompatibility = '1.8'
}
task generateSource (type: JavaCompile) { //second pass, uses the compiled annotation processor to generate source code
dependsOn 'compileAnnotationProcessor'
source sourceSets.main.java
destinationDir sourceSets.main.java.outputDir
classpath = sourceSets.main.compileClasspath + fileTree(dir: sourceSets.main.java.outputDir)
options.compilerArgs += [
"-processor",
"com.[company].svc.tools.codegen.AnnotationProcessor,com.[company].logging.processor.Processor"
]
}
I’ve tried several other methods as well, including several variations of
dependencies {
annotationProcessor
}
And still nothing works. I usually return this error:
Execution failed for task ':[company]:generateSource'.
Annotation processor 'com.[company].svc.tools.codegen.AnnotationProcessor' not found
but when I look at my debug output, my -processorpath and -classpath both include …/[projectdir]/build/classes/java/main/com/[company]/svc/tools/codegen/AnnotationProcessor.class or .java.
I suspect the issue may have something with out project not using typical gradle file structure (“src/com/[company]” instead of “src/main/java”), so I have also been trying different sourceSets. Here is what I have:
sourceSets {
main {
java {
srcDirs 'src'
}
resources {
srcDirs 'resources', 'src'
include '**/*.xml'
include '**/*.properties'
include '**/*.vm'
}
}
test {
java {
srcDirs 'test'
}
}
}
What is the best method to use a local annotation processor? It works in ant, although I clearly don’t understand why