본문 바로가기
개발일지/문제 해결

./mvnw clean compile package 명령 시 Fatal error compiling: invalid target release: 11 에러 해결

2022. 8. 17.

인텔리j 터미널에서

프로젝트 위치에서

./mvnw clean compile package

명령어를 입력했는데 다음과 같이 에러가 발생한다.

PS C:\Users\taekg\IdeaProjects\Inflearn\msa\firstService> ./mvnw clean compile package
[INFO] Scanning for projects...
[INFO] 
[INFO] ---------------------< com.example:first-service >----------------------
[INFO] Building first-service 0.0.1-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO] 
[INFO] --- maven-clean-plugin:3.1.0:clean (default-clean) @ first-service ---
[INFO] Deleting C:\Users\taekg\IdeaProjects\Inflearn\msa\firstService\target
[INFO] 
[INFO] --- maven-resources-plugin:3.2.0:resources (default-resources) @ first-service ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Using 'UTF-8' encoding to copy filtered properties files.
[INFO] Copying 1 resource
[INFO] Copying 0 resource
[INFO]
[INFO] --- maven-compiler-plugin:3.8.1:compile (default-compile) @ first-service ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 2 source files to C:\Users\taekg\IdeaProjects\Inflearn\msa\firstService\target\classes
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  1.714 s
[INFO] Finished at: 2022-08-17T18:33:39+09:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (default-compile) on project first-service: Fatal error compiling: invalid target release: 11 -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException

Fatal error compiling: invalid target release: 11을 검색해본 결과

메이븐 프로젝트 컴파일 시 뜨는 에러였다.

즉, 자바 11버전의 소스파일은 현재 서버에서 컴파일 할 수 없다는 것이다.

pom.xml 에는 소스 컴파일 세팅이 jdk11 버전으로 맞춰져 있고 리눅스 서버의 자바 버전은 1.8로 맞춰진 상태이다.

즉, 11 버전의 소스파일을 더 낮은 버전인 1.8로 컴파일 하려니까 컴파일 에러가 뜬다.

 

나는 default를 1.8로 사용할 것이기 때문에

pom.xml 에 있는 자바 버전을 1.8로 변경해 주면된다.

만약에 11로 사용해야한다면 리눅스 자바 버전을 11로 해주면 된다.

메이븐 자바 버전은 아래 처럼 ./mvnw -version으로 확인가능하다.

PS C:\Users\taekg\IdeaProjects\Inflearn\msa\firstService> ./mvnw -version
Apache Maven 3.8.6 (84538c9988a25aec085021c365c560670ad80f63)
Maven home: C:\Users\taekg\.m2\wrapper\dists\apache-maven-3.8.6-bin\1ks0nkde5v1pk9vtc31i9d0lcd\apache-maven-3.8.6
Java version: 1.8.0_322, vendor: Azul Systems, Inc., runtime: C:\Program Files\Zulu\zulu-8\jre
Default locale: ko_KR, platform encoding: MS949
OS name: "windows 10", version: "10.0", arch: "amd64", family: "windows"

참고로 mvnw란 Maven을 설치하지 않아도 Maven을 실행시킬 수 있도록 해주는 유닉스 셸 스크립트이다.