For a completed project, SpringBoot + Lombok + MapStruct in 2025-01. (see version in pom)
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.4.1</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.redfrog</groupId>
<artifactId>demo-mapstruct</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>demo-mapstruct</name>
<description>demo-mapstruct</description>
<url/>
<licenses>
<license/>
</licenses>
<developers>
<developer/>
</developers>
<scm>
<connection/>
<developerConnection/>
<tag/>
<url/>
</scm>
<properties>
<java.version>21</java.version>
<!-- <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>-->
<!-- <maven.compiler.source>1.8</maven.compiler.source>-->
<!-- <maven.compiler.target>1.8</maven.compiler.target>-->
<org.mapstruct.version>1.6.3</org.mapstruct.version>
<!-- <org.projectlombok.version>1.18.36</org.projectlombok.version>-->
<lombok-mapstruct-binding.version>0.2.0</lombok-mapstruct-binding.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<scope>provided</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mapstruct</groupId>
<artifactId>mapstruct</artifactId>
<version>${org.mapstruct.version}</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<annotationProcessorPaths>
<path>
<groupId>org.mapstruct</groupId>
<artifactId>mapstruct-processor</artifactId>
<version>${org.mapstruct.version}</version>
</path>
<path>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</path>
<path>
<groupId>org.projectlombok</groupId>
<artifactId>lombok-mapstruct-binding</artifactId>
<version>${lombok-mapstruct-binding.version}</version>
</path>
</annotationProcessorPaths>
</configuration>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<excludes>
<exclude>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</exclude>
</excludes>
</configuration>
</plugin>
</plugins>
</build>
</project>
Note:
in intellij, you may need to enable annotation processing
, and:
either Obtain processors from project classpath
or locate the jar file manually by Processor path:
C:\Users\nshln\.m2\repository\org\mapstruct\mapstruct-processor\1.6.3\mapstruct-processor-1.6.3.jar
;C:\Users\nshln\.m2\repository\org\mapstruct\mapstruct\1.6.3\mapstruct-1.6.3.jar
;C:\Users\nshln\.m2\repository\org\projectlombok\lombok\1.18.36\lombok-1.18.36.jar
;C:\Users\nshln\.m2\repository\org\projectlombok\lombok-mapstruct-binding\0.2.0\lombok-mapstruct-binding-0.2.0.jar
do not attempt to remove the <artifactId>lombok-mapstruct-binding</artifactId>
(at least didnt work for me)
do not attempt to put the <artifactId>mapstruct-processor</artifactId>
in <dependency>
(at least didnt work for me)
Reference
https://github.com/mapstruct/mapstruct-examples/blob/main/mapstruct-lombok/pom.xml
// Quick Guide to MapStruct | Baeldung
// https://www.baeldung.com/mapstruct
//
// java - MapStruct - Cannot find implementation - Stack Overflow
// https://stackoverflow.com/questions/61710510/mapstruct-cannot-find-implementation
//
// https://www.aliyun.com/sswb/541358.html
//
// https://developer.aliyun.com/article/1350244?spm=5176.26934562.main.2.69cc72eeT6HBiK
//
// Lombok/Mapstruct problem: Cannot find symbol · Issue #1270 · mapstruct/mapstruct
// https://github.com/mapstruct/mapstruct/issues/1270
//
// https://github.com/ichengzi/ichengzi.github.io/issues/46
//
// java - What is the best way to convert entity to dto? For Spring REST API Application - Stack Overflow
// https://stackoverflow.com/questions/69364258/what-is-the-best-way-to-convert-entity-to-dto-for-spring-rest-api-application
//
// Spring Boot Mapstruct | Lombok & Mapstruct with Spring Boot CRUD API | Java Bean Mappings - YouTube
// https://www.youtube.com/watch?v=EVCrLp-k494
//
// java - Upgrading to Spring Boot 3 causing annotation processing errors - Stack Overflow
// https://stackoverflow.com/questions/79288971/upgrading-to-spring-boot-3-causing-annotation-processing-errors
//
// [BUG] lombok 1.18.30 with Mapsrtruct 1.5.5.Final with Java 21 Fails to work! (made tests) · Issue #3569 · projectlombok/lombok
// https://github.com/projectlombok/lombok/issues/3569
//
// mapstruct-examples/mapstruct-lombok/pom.xml at main · mapstruct/mapstruct-examples
// https://github.com/mapstruct/mapstruct-examples/blob/main/mapstruct-lombok/pom.xml
//
// Frequently Asked Questions (FAQ) – MapStruct
// https://mapstruct.org/faq/
//
// Maven Central: org.projectlombok:lombok-mapstruct-binding
// https://central.sonatype.com/artifact/org.projectlombok/lombok-mapstruct-binding?smo=true
//
// MapStruct 1.6.3 Reference Guide
// https://mapstruct.org/documentation/stable/reference/html/