我有一个带有3个子模块的Maven项目:其中2个应使用java8编译,其中一个应使用java11编译。运行maven时,我的主要JAVA_HOME环境变量设置为安装在计算机中的JDK 8。我想指定仅将jdk 11用于需要它的特定子模块,但无法使其工作。
在POM父亲中,我有以下
<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>
</configuration>
</plugin>
在需要jdk 11的特定子项目中,我尝试按照本文档http://maven.apache.org/plugins/maven-compiler-plugin/examples/compile-using-different-jdk.html进行设置,所以我有了
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<release>11</release>
<verbose>true</verbose>
<fork>true</fork>
<executable>${JAVA_11_HOME}/bin/javac</executable>
</configuration>
</plugin>
并且在我的settings.xml中设置了JAVA_11_HOME变量(根据文档)
当我运行编译(整个项目或单个java11子模块)时,都会得到
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile
(default-compile) on project features-serving: Compilation failure -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal
org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (default-compile) on project
features-serving: Compilation failure
如果在启用调试和堆栈跟踪的情况下运行,则不会获得任何有用的信息。基本上我无法弄清楚出了什么问题。我唯一确定的是,maven可以从我的settings.xml文件中正确拾取JDK 11路径。