[서버][스프링] Mapstruct와 Lombok 동시 사용할 때 주의할 점
의외의 동작이긴 하지만 pom(maven)을 이용하는 경우 mapstruct와 lombok을 동시에 사용 할 때
annotationProcessorPaths에 명시하는 순서가 중요한 것 같습니다.
mapstruct 를 먼저 적고 그 다음에 lombok을 쓰고..
클래스의 package 위치 등을 변경하고 빌드하면 Unknown Property in a return type 같은 에러가 발생합니다.
몇 번 테스트한 걸로 보면.. lombok이 실행되기 전에 mapstruct 관련된 어노테이션 프로세서가 동작해서 그런 것 같습니다.
설마? 하고 아래처럼 두 순서를 변경하니
에러가 마법처럼 사라지네요.
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>1.8</source> <!-- depending on your project -->
<target>1.8</target> <!-- depending on your project -->
<annotationProcessorPaths>
<path>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>${org.projectlombok.version}</version>
</path>
<path>
<groupId>org.mapstruct</groupId>
<artifactId>mapstruct-processor</artifactId>
<version>${org.mapstruct.version}</version>
</path>
</annotationProcessorPaths>
</configuration>
</plugin>
</plugins>
</build>
참고
mapstruct.org/documentation/installation/
Installation – MapStruct
Installation Distribution Bundle You can obtain a distribution bundle containing the MapStruct binaries, source code and API documentation from GitHub. Apache Maven If you’re using Maven to build your project add the following to your pom.xml to use MapS
mapstruct.org
stackoverflow.com/questions/47676369/mapstruct-and-lombok-not-working-together
MapStruct and Lombok not working together
Tech Stack being used : Java 8 MapStruct : 1.2.0.Final Lombok: 1.16.18 IDE: IntelliJ - Lombok Plugin already installed Initially, I faced issues when I removed getters and setters and added @Ge...
stackoverflow.com
댓글 영역