Contents
see List이클립스 Maven Update Project 시 자바 버전 변경 방지
Maven Update Project를 실행할 때마다 Java 버전이 1.5로 변경되는 문제를 해결하는 방법입니다.
문제 상황
Maven Update Project (Alt+F5) 실행 후 Java 컴파일러 버전이 의도치 않게 변경됩니다.
해결 방법
pom.xml에 maven-compiler-plugin 설정을 추가합니다.
pom.xml 설정
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
</plugins>
</build>
Java 11 이상인 경우
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.11.0</version>
<configuration>
<release>11</release>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
properties 방식 (간단한 방법)
<properties>
<java.version>1.8</java.version>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
Spring Boot 프로젝트
<properties>
<java.version>11</java.version>
</properties>
적용 후 확인
- pom.xml 저장
- 프로젝트 우클릭 → Maven → Update Project (Alt+F5)
- 프로젝트 우클릭 → Properties → Java Compiler에서 버전 확인
추가 팁
- 이클립스 재시작이 필요할 수 있음
- .settings 폴더의 org.eclipse.jdt.core.prefs 파일에서 버전 확인 가능
- Update Project 시 "Force Update of Snapshots/Releases" 체크 권장
.classpath 파일 확인
<!-- JRE System Library 버전 확인 -->
<classpathentry kind="con"
path="org.eclipse.jdt.launching.JRE_CONTAINER/
org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>