[서버][스프링][Kotlin][mapstruct] package com.dreamaz.gongga.room.model.RoomDto does not exist
문제 현상
mvn compile을 통해 kotlin 프로젝트를 빌드하면
빌드 중에 mapstruct 관련 annotation proccessor에서 일반 클래스들을 못찾는 아래의 에러가 발생했습니다.
원인
target/classes 폴더를 보면 아직 *.class 파일이 생성되지 않아 생긴 문제로 보입니다.
해결 방법
maven-compiler-plugin에 아래의 코드를 추가하면 됩니다.
*변경 전 컴파일 단계
maven-resources-plugin:3.0.1:copy-resources (copy-resources)
kotlin-maven-plugin:1.4.31:kapt (kapt)
maven-resources-plugin:3.0.1:resources (default-resources)
maven-compiler-plugin:3.8.1:compile (default-compile)
*변경 후 컴파일 단계
maven-resources-plugin:3.0.1:copy-resources (copy-resources)
kotlin-maven-plugin:1.4.31:kapt (kapt)
maven-resources-plugin:3.0.1:resources (default-resources)
maven-compiler-plugin:3.8.1:compile (java-compile)
*전체 코드(복붙용)
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<proc>none</proc>
<source>${kotlin.compiler.jvmTarget}</source>
<target>${kotlin.compiler.jvmTarget}</target>
<source>1.8</source> <!-- depending on your project -->
<target>1.8</target> <!-- depending on your project -->
</configuration>
<executions>
<!-- Replacing default-compile as it is treated specially by maven -->
<execution>
<id>default-compile</id>
<phase>none</phase>
</execution>
<!-- Replacing default-testCompile as it is treated specially by maven -->
<execution>
<id>default-testCompile</id>
<phase>none</phase>
</execution>
<execution>
<id>java-compile</id>
<phase>compile</phase>
<goals>
<goal>compile</goal>
</goals>
</execution>
<execution>
<id>java-test-compile</id>
<phase>test-compile</phase>
<goals> <goal>testCompile</goal> </goals>
</execution>
</executions>
</plugin>
참고
kotlinlang.org/docs/maven.html#compile-kotlin-and-java-sources
www.baeldung.com/kotlin/maven-java-project
댓글 영역