I was trying to add MapStruct to a Micronaut project with a build file like:
plugins {
id "io.spring.dependency-management" version "1.0.6.RELEASE"
id "com.github.johnrengelman.shadow" version "4.0.2"
id "net.ltgt.apt-eclipse" version "0.18"
id "net.ltgt.apt-idea" version "0.18"
}
dependencies {
annotationProcessor("io.micronaut:micronaut-inject-java")
annotationProcessor("io.micronaut:micronaut-security")
annotationProcessor("io.micronaut:micronaut-validation")
annotationProcessor("org.mapstruct:mapstruct-processor:${mapstructVersion}")
..
}
tasks.withType(JavaCompile) {
options.encoding = "UTF-8"
options.compilerArgs = [
'-parameters',
'-Amapstruct.suppressGeneratorTimestamp=true',
'-Amapstruct.suppressGeneratorVersionInfoComment=true',
'-Amapstruct.defaultComponentModel=default'
]
}
However the Mapstruct annotation processor does not kick in when using gw clean run
Now when I remove the Micronaut annotation processors (3) than the Mapstruct one seems to kick in. and the mapper impl is genereated...
Also when I move the MapStruct ap to the top of the list if is also working.
Is Micronaut doing special with the annotation processing?
Think this is simply the same as the Lombok stuff. Any annotation processors used by the app have to be configured before Micronaut as you have done.
Why should any annotation processor used by the app need to be configured before Micronaut? Is Micronaut claiming all annotations?
Lombok is a special type of processor that changes the classes that are annotated. MapStruct is a normal processor that creates new classes and works when run in multiple rounds.
P.S. I am the MapStruct project lead and we would gladly do something on our side if it is needed for this to work seamlessly with Micronaut
I need to investigate further, I know we return false here which indicates no further processing https://github.com/micronaut-projects/micronaut-core/blob/master/inject-java/src/main/java/io/micronaut/annotation/processing/BeanDefinitionInjectProcessor.java#L218
So maybe that is the issue on the Micronaut side. If we change that we have to verify it doesn't break anything in Micronaut.
I think using false is correct. From the Javadoc:
Processes a set of annotation types on type elements originating from the prior round and returns whether or not these annotation types are claimed by this processor. If
trueis returned, the annotation types are claimed and subsequent processors will not be asked to process them; iffalseis returned, the annotation types are unclaimed and subsequent processors may be asked to process them. A processor may always return the same boolean value or may vary the result based on chosen criteria.
We are also returning false in the MapStruct processor. I initially thought that you were returning true, but that is not the case.
Right, I guess I got it the wrong way round in my head. So in that case I don't see what we are doing wrong just yet. I will have to investigate further through debugging.
It would be interesting to see what happens when maven used, just to rule out that Gradle is not doing something weird.
Indeed. We have had issues with Gradle's handling of annotation processors in the past
Was working on another project (https://github.com/flowable/flowable-serverless) with our own annotation processor and we saw the exact same problem. This was with maven though. I haven't had the time to debug why our annotation processor was not being invoked. I hope that we can figure out soon why this is happening.
@filiphr I will investigate this soon...