3

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>

2 Answers 2

1

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>
Sign up to request clarification or add additional context in comments.

Comments

-1

If your lombok and mapstruct don't play well with each other, you can use lombok-mapstruct-binding to resolve the conflict (You don't need to put it in the execution tag). The key is to include the binding artifact in the same place with the lombok and mapstruct annotation processors configuration. It works splendid in my case!

<build>
  <plugins>
    <plugin>
      ..
      <configuration>
        ..
        <annotationProcessorPaths>
        <path>
          <groupId>org.projectlombok</groupId>
          <artifactId>lombok</artifactId>
          <version>1.18.20</version>
        </path>
        <path>
          <groupId>org.projectlombok</groupId>
          <artifactId>lombok-mapstruct-binding</artifactId>
          <version>0.2.0</version>
        </path>
        <path>
          <groupId>org.mapstruct</groupId>
          <artifactId>mapstruct-processor</artifactId>
          <version>1.4.2.Final</version>
        </path>
      </annotationProcessorPaths>
    </plugin>
  <plugins>
<build>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.