I extended the AbstractProcessor to create an annotation processor to generate a class in Java and it works fine.
The first issue is: the class only is generated for the second time I run ./gradlew build
.
The second issue (that my be related to the first one) Gradle won’t compile if I have some code that is dependent of the generated class. It throws:
> Task :compileJava FAILED
/src/main/java/me/fouyer/Main.java:6: error: cannot find symbol
My build.gradle
plugins {
id 'java'
}
group = 'me.fouyer'
version = '1.0.0'
repositories {
mavenCentral()
}
dependencies {
implementation 'com.google.auto.service:auto-service:1.1.1'
annotationProcessor('me.fouyer:annotation:1.0.0')
}
I already tried:
- Using Google’s Auto Service.
- Removing Google’s Auto Service and creating
src/resources/META-INF/services/javax.annotation.processing.Processor
manually. - Running on terminal or by IntelliJ’s interface
- Gradle can not compile the code with the generated sources by annotationProcessor He had the same issue, but in his case the error was on generating the file. But I tried to copy his
build.gradle
but the taskpreProcessAnnotation
is a little bit confusing for me on what it does and how could I change it for my scenario. - Adding the path to the generated sources using SourceSets
I created a repository with a minimal, reproducible example where I have the annotation, the annotation processor and a Person class that uses the annotation. GitHub