我的机器上有jdk 7和8,JAVA_HOME指向java 7,Jenkins使用java 8。我创建了一个maven项目,我试图使用java 8在jenkins上构建它,但出现以下错误:
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (default-compile) on project maven-demo: Compilation failure -> [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/MojoFailureException
Build step 'Invoke top-level Maven targets' marked build as failure
Finished: FAILURE
在 pom.xml 中我添加了以下内容:
<properties>
<maven.compiler.target>1.8</maven.compiler.target>
<maven.compiler.source>1.8</maven.compiler.source>
</properties>
和
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<verbose>true</verbose>
<fork>true</fork>
<source>1.8</source>
<target>1.8</target>
<executable>path/to/jdk/bin/javac</executable>
</configuration>
</plugin>
</plugins>
</build>
但使用上述 2 种方法中的任何一种,我仍然遇到相同的错误。
如何更新它以使 maven 使用 java 8 ?
最佳答案
您必须在全局工具配置下使用不同 jdks 的名称和 JAVA_HOME 配置 Jenkins。 http://path-to-your-jenkins:8080/configureTools/ 。 然后你可以在你的项目配置中选择JDK http://path-to-your-jenkins:8080/job/yourJob/configure 。在“常规”选项卡中的 JDK 字段中。
关于java - 如何让maven和jenkins使用特定的jdk?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54906508/