Annotation Processor '' not found, but the processor is clearly in the class path


This is a project I am migrating from ant. The project includes a class, 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 and puts it in
  classpath = sourceSets.main.compileClasspath
  sourceCompatibility = '1.8'
  targetCompatibility = '1.8'
task generateSource (type: JavaCompile) { //second pass, uses the compiled annotation processor to generate source code
  dependsOn 'compileAnnotationProcessor'
  classpath = sourceSets.main.compileClasspath + fileTree(dir:
  options.compilerArgs += [

I’ve tried several other methods as well, including several variations of

dependencies {

And still nothing works. I usually return this error:

Execution failed for task ':[company]:generateSource'.
Annotation processor 'com.[company]' 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 :frowning:

You can’t do circular inputs like that (i.e. the task taking its own output as an input). The compile task will clean up its outputs before it runs, which means it’ll delete the processor.

Instead, either put your processor into a separate project or at the least into a different sourceSet.

I would love to reorganize the project, but its a monolithic legacy nightmare. The idea is that is populated by the first compilation. The second task then uses it as input, then overwrites it with the generated code.

You can’t do that, simply put. Just use a different output dir for compiling the processor and exclude its sources from the second compile task.