Compile code with generated source by annotation processor

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:

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

You have a hen-and-egg problem.
You cannot use the annotation processor within the same build that builds the annotation processor.
That’s like when you try to use a Gradle plugin to build a project that builds that very Gradle plugin.
That just cannot work except if you use a pre-built version from somewhere like in your described procedure.