mapstruct / mapstruct-examples

Examples for using MapStruct
Other
1.28k stars 511 forks source link

Occasional Maven build failures with Lombok + MapStruct #131

Closed pc-mzhou closed 2 years ago

pc-mzhou commented 2 years ago

We have a Maven-managed Spring Boot project that uses both Lombok and MapStruct, whose pom.xml file follows exactly these instructions laid out here https://mapstruct.org/documentation/stable/reference/html/#_set_up as well as the sample project https://github.com/mapstruct/mapstruct-examples/tree/master/mapstruct-lombok

The build fails from time to time if I execute mvn clean install -DskipTests. When it failed, I found that none of the Lombok annotated methods (getters/setters/builders etc) were generated therefore java compiler could not find those methods when compiling the MapStruct mapper implementations. When it succeeded, every Lombok method was generated. What baffled me is that the build will magically work again after a while, without me doing anything. So it's hard to characterize what failed the build.

Our related setup:

java: 11.0.13-zulu
maven: 3.8.4
spring boot: 2.1.17.RELEASE
spring framework: 5.1.17.RELEASE
mapstruct: 1.4.2.Final
lombok-mapstruct-binding: 0.2.0

Here is a snippet of our pom.xml on java compiler plugin

                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-compiler-plugin</artifactId>
                    <version>${maven-compiler-plugin.version}</version>
                    <configuration>
                        <release>${java-api.version}</release>
                        <optimize>false</optimize>
                        <debug>true</debug>
                        <debuglevel>lines,vars,source</debuglevel>
                        <fork>true</fork>
                        <meminitial>128m</meminitial>
                        <maxmem>1024m</maxmem>
                        <annotationProcessorPaths>
                            <path>
                                <groupId>org.mapstruct</groupId>
                                <artifactId>mapstruct-processor</artifactId>
                                <version>${org.mapstruct.version}</version>
                            </path>
                            <path>
                                <groupId>org.projectlombok</groupId>
                                <artifactId>lombok</artifactId>
                                <version>${lombok.version}</version>
                            </path>
                            <path>
                                <groupId>org.projectlombok</groupId>
                                <artifactId>lombok-mapstruct-binding</artifactId>
                                <version>${lombok-mapstruct-binding.version}</version>
                            </path>
                        </annotationProcessorPaths>
                    </configuration>
                </plugin>
pc-mzhou commented 2 years ago

One thing I had suspicion of is the computer on which I build my project. I have a newer MacBook Pro (and Apple silicon) than my coworkers who don't experience this issue on their older Macs.

MacBook Pro (14-inch, 2021)
chip: Apple M1 Pro
OS: macOS Monterey version 12.1
filiphr commented 2 years ago

When it failed, I found that none of the Lombok annotated methods (getters/setters/builders etc) were generated therefore java compiler could not find those methods when compiling the MapStruct mapper implementations.

If this is the case when it fails then the failure has nothing to do with MapStruct and everything to do with Lombok. I would suggest you to raise an issue about it in the Lombok issue tracker. It could be related to the Java you are using for the Apple silicon.

pc-mzhou commented 2 years ago

@filiphr Thanks for the pointers.