[증상]

maven으로 잘 빌드되던 프로젝트에서 JDK 24를 설치후 빌드시 아래와 같은 경고가 발생하고 빌드에 실패함

$ mvn clean install -U -Dmaven.test.skip=true
WARNING: A restricted method in java.lang.System has been called
WARNING: java.lang.System::load has been called by org.fusesource.jansi.internal.JansiLoader in an unnamed module (file:/opt/homebrew/Cellar/maven/3.9.9/libexec/lib/jansi-2.4.1.jar)
WARNING: Use --enable-native-access=ALL-UNNAMED to avoid a warning for callers in this module
WARNING: Restricted methods will be blocked in a future release unless native access is enabled

WARNING: A terminally deprecated method in sun.misc.Unsafe has been called
WARNING: sun.misc.Unsafe::objectFieldOffset has been called by com.google.common.util.concurrent.AbstractFuture$UnsafeAtomicHelper (file:/opt/homebrew/Cellar/maven/3.9.9/libexec/lib/guava-33.2.1-jre.jar)
WARNING: Please consider reporting this to the maintainers of class com.google.common.util.concurrent.AbstractFuture$UnsafeAtomicHelper
WARNING: sun.misc.Unsafe::objectFieldOffset will be removed in a future release
[INFO] Scanning for projects...
[INFO] 
[INFO] --------------< com.demo:sample >--------------
[INFO] Building sample 3.4.3-SNAPSHOT
[INFO]   from pom.xml
[INFO] --------------------------------[ jar ]---------------------------------
[INFO] 
[INFO] --- clean:3.4.1:clean (default-clean) @ sample ---
[INFO] Deleting /Users/deepfree/development/workspace-java/sample/target
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  4.171 s
[INFO] Finished at: 2025-04-02T17:40:52+09:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-clean-plugin:3.4.1:clean (default-clean) on project sample: Failed to clean project: Failed to delete /Users/deepfree/development/workspace-java/sample/target/generated-sources/annotations -> [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

 

뿐만 아니라 mvn의 버전만 확인해도 동일한 경고 발생

// mvn 도구에서 제한된 메소드 java.lang.System이 호출되었다는 경고
$ mvn --version                                                                                          1 ↵  10037  17:35:22
WARNING: A restricted method in java.lang.System has been called
WARNING: java.lang.System::load has been called by org.fusesource.jansi.internal.JansiLoader in an unnamed module (file:/opt/homebrew/Cellar/maven/3.9.9/libexec/lib/jansi-2.4.1.jar)
WARNING: Use --enable-native-access=ALL-UNNAMED to avoid a warning for callers in this module
WARNING: Restricted methods will be blocked in a future release unless native access is enabled

Apache Maven 3.9.9 (8e8579a9e76f7d015ee5ec7bfcdc97d260186937)
Maven home: /opt/homebrew/Cellar/maven/3.9.9/libexec
Java version: 24, vendor: Eclipse Adoptium, runtime: /Library/Java/JavaVirtualMachines/temurin-24.jdk/Contents/Home
Default locale: ko_KR, platform encoding: UTF-8
OS name: "mac os x", version: "15.3.2", arch: "aarch64", family: "mac"

// root 권한으로 실행시 정상
$ sudo mvn --version
Apache Maven 3.9.9 (8e8579a9e76f7d015ee5ec7bfcdc97d260186937)
Maven home: /opt/homebrew/Cellar/maven/3.9.9/libexec
Java version: 23.0.2, vendor: Homebrew, runtime: /opt/homebrew/Cellar/openjdk/23.0.2/libexec/openjdk.jdk/Contents/Home
Default locale: ko_KR, platform encoding: UTF-8
OS name: "mac os x", version: "15.3.2", arch: "aarch64", family: "mac"

 

[원인]

maven 도구의 jansi가 console에서 Ansi를 사용하기 위해 시스템에 접근해서 해당 이슈가 발생하는 것으로 판단됨

maven/3.9.9/libexec/lib/jansi-2.4.1.jar

 

[해결방안]

maven 3에서:

# MAVEN_OPTS 지정
export MAVEN_OPTS="--enable-native-access=ALL-UNNAMED"

 

zsh에 기본으로 적용하려면 ~/.zshrc 에 위의 설정을 적용하면 기본 쉘환경에 적용됨

현재 열려있는 쉘에 적용하려면 source ~/.zshrc 를 실행하여 적용

 

maven 4에서:

해당 이슈가 Apache Maven 프로젝트에 보고되어 https://issues.apache.org/jira/browse/MNG-8399?page=com.atlassian.jira.plugin.system.issuetabpanels%3Acomment-tabpanel&focusedCommentId=17939366 에서 찾을 수 있고, jansi는 maven 4에서 더이상 이슈가 되지 않는다는 4일전에 작성된 댓글에서 확인이 가능합니다

 

maven 4에서는 "--enable-native-access=ALL-UNNAMED" 옵션 지정이 필요없을 것으로 보입니다

하지만 아직 brew에는 maven 3.9.9까지만 배포되고 있습니다

+ Recent posts