I used Eclipse IDE to develop an application that uses Mapstruct and I'm moving now to IntelliJ to continue the development.
Everything worked fine on Eclipse but I have an unexpected behavior on IntelliJ due to the usage of annotationProcessorPaths.
My configuration is as below :
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<annotationProcessorPaths>
<path>
<groupId>org.mapstruct</groupId>
<artifactId>mapstruct-processor</artifactId>
<version>${mapstruct.version}</version>
</path>
</annotationProcessorPaths>
<source>${java.version}</source>
<target>${java.version}</target>
<compilerArgs>
<compilerArg>
-Amapstruct.defaultComponentModel=${mapstruct.defaultComponentModel}
</compilerArg>
<compilerArg>
-Aorg.hibernate.jpamodelgen.JPAMetaModelEntityProcessor
</compilerArg>
</compilerArgs>
</configuration>
On IntelliJ, When I launch a Maven clean install I get the generated source :
@Component
public class FieldMapperImpl implements FieldMapper {
@Autowired
private FieldMapperResolver fieldMapperResolver;
...
}
But when I run/debug my Spring Boot app, the generated source I get is :
public class FieldMapperImpl implements FieldMapper {
private final FieldMapperResolver fieldMapperResolver = new FieldMapperResolver();
...
}
How can I solve this problem ?
I assume that you are running/debugging the Spring Boot app via IntelliJ directly. The reason why that is happening is because IntelliJ does not pick up the configuration from the maven-compiler-plugin. See IDEA-143742 and IDEA-150621.
You will also have to configure the IntelliJ Annotation Processor Options separately. You can find that in Settings -> Build, Execution, Deployment -> Compiler -> Annotation Processors
It is strange how IntelliJ even invokes the processor, do you have the mapstruct-processor also as a dependency in your pom?
Edit:
IntelliJ does not pick up the maven-compiler-plugin compiler arguments. The default component model is set via the annotation processor options. In order for IntelliJ to correctly work one should either set the same property in the IntelliJ configuration or use @Mapper(componentModel = "spring"). More info in the documentation
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With