I have a spring boot project that has lombok and mapstruct and uses maven as the build tool. I need the annotations to be processed at compile time with the resultant generated sources packaged with the final jar. The build is successful. However, the final jar is missing the mapstruct implementation class. The error when I try to start the spring boot application is:
APPLICATION FAILED TO START
Description:
Field salesforceObjectMapper in com.some_org.service.salesforce.object.processor.SalesforceObjectProcessor required a bean of type 'com.some_org.service.salesforce.object.mapper.SalesforceObjectMapper' that could not be found.
Action:
Consider defining a bean of type 'com.some_org.service.salesforce.object.mapper.SalesforceObjectMapper' in your configuration.
Here is my maven-compiler-plugin setup:
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.7.0</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<annotationProcessorPaths>
<path>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.12</version>
</path>
<path>
<groupId>org.mapstruct</groupId>
<artifactId>mapstruct-processor</artifactId>
<version>1.2.0.Final</version>
</path>
</annotationProcessorPaths>
<compilerArgs>
<compilerArg>-Amapstruct.suppressGeneratorTimestamp=true</compilerArg>
<compilerArg>-Amapstruct.suppressGeneratorVersionInfoComment=true</compilerArg>
</compilerArgs>
</configuration>
</plugin>
Eventually resolved this by overriding the default compile goal during the compile phase using execution as shown below:
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.7.0</version>
<executions>
<execution>
<id>Compile With Annotation Processing</id>
<phase>compile</phase>
<goals>
<goal>compile</goal>
</goals>
<configuration>
<source>1.8</source>
<target>1.8</target>
<annotationProcessorPaths>
<path>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.12</version>
</path>
<path>
<groupId>org.mapstruct</groupId>
<artifactId>mapstruct-processor</artifactId>
<version>1.2.0.Final</version>
</path>
</annotationProcessorPaths>
<compilerArgs>
<compilerArg>-Amapstruct.suppressGeneratorTimestamp=true</compilerArg>
<compilerArg>-Amapstruct.suppressGeneratorVersionInfoComment=true</compilerArg>
</compilerArgs>
</configuration>
</execution>
</executions>
</plugin>
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