- Maven版本要3.6.0以上
- Lombok版本要1.16.16以上(但是看下面的实例,发现 1.18.12 是可以的,一旦改成 1.18.24 打包也能通过,但是发现转化的时候属性都是 null)
- (仅针对方案一)另外编译的 Lombok、Mapstruct 的插件不要忘记加上,否则会引发如下报错:
No property named “XXX“ exists in source parameter(s). Did you mean “null“?
解决方案
方案一
<properties>
<>UTF-8</>
<>1.8</>
<>1.8</>
<>1.4.</>
<>1.18.12</>
</properties>
<dependencies>
<dependency>
<groupId></groupId>
<artifactId>mapstruct</artifactId>
<version>${}</version>
</dependency>
<!-- lombok dependencies should not end up on classpath -->
<dependency>
<groupId></groupId>
<artifactId>lombok</artifactId>
<version>${}</version>
<scope>provided</scope>
</dependency>
<!-- idea 2018.1.1 之前的版本需要添加下面的配置,后期的版本就不需要了,可以注释掉,
我自己用的2019.3 -->
<dependency>
<groupId></groupId>
<artifactId>mapstruct-processor</artifactId>
<version>${}</version>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId></groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<annotationProcessorPaths>
<path>
<groupId></groupId>
<artifactId>lombok</artifactId>
<version>${}</version>
</path>
<path>
<groupId></groupId>
<artifactId>mapstruct-processor</artifactId>
<version>${}</version>
</path>
</annotationProcessorPaths>
</configuration>
</plugin>
</plugins>
</build>
方案二
<properties>
<>UTF-8</>
<>1.8</>
<>1.8</>
<>1.4.</>
<>1.18.12</>
</properties>
<dependencies>
<dependency>
<groupId></groupId>
<artifactId>mapstruct-jdk8</artifactId>
<version>${}</version>
</dependency>
<!-- lombok dependencies should not end up on classpath -->
<dependency>
<groupId></groupId>
<artifactId>lombok</artifactId>
<version>${}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId></groupId>
<artifactId>mapstruct-processor</artifactId>
<version>${}</version>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId></groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>