Gradle "Annotation processors must be declared via the annotationProcessor configuration" - Fix in CI
Since Gradle 5, annotation processors must be put on the dedicated annotationProcessor configuration, not the compile classpath. A processor found on implementation/compileOnly is ignored - so generated code never appears, and a strict build fails.
What this error means
Compilation warns Annotation processors must be explicitly declared now. The following files contain annotation processors ... and downstream code fails with cannot find symbol for classes that should have been generated.
> Task :compileJava
warning: Annotation processing is enabled because one or more processors were
found on the class path. ... Annotation processors must be explicitly declared
now. The following dependencies on the compile classpath are found to contain
annotation processors: 'org.mapstruct:mapstruct-processor:1.6.0'.Common causes
Processor on the wrong configuration
The processor jar is declared as implementation or compileOnly, so Gradle no longer auto-runs it.
Only the API jar is present
The annotations (API) are on the classpath but the matching processor was never added to annotationProcessor.
Mixed module setup
In a multi-module build the processor was added to one module but the consuming module compiles the annotated code.
How to fix it
Declare the processor on annotationProcessor
Add the processor to the dedicated configuration so Gradle runs it.
dependencies {
implementation 'org.mapstruct:mapstruct:1.6.0'
annotationProcessor 'org.mapstruct:mapstruct-processor:1.6.0'
}Pair Lombok API and processor
Lombok needs both compileOnly (API) and annotationProcessor (the processor).
dependencies {
compileOnly 'org.projectlombok:lombok:1.18.34'
annotationProcessor 'org.projectlombok:lombok:1.18.34'
}Add it for tests too
Processors used by test sources need the testAnnotationProcessor configuration.
dependencies {
testAnnotationProcessor 'org.mapstruct:mapstruct-processor:1.6.0'
}How to prevent it
- Always put processors on
annotationProcessor/testAnnotationProcessor. - Keep the API and processor versions in lockstep.
- Add processors in every module that compiles the annotated sources.