java - 如何让maven和jenkins使用特定的jdk?

标签 java maven jenkins

我的机器上有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/

相关文章:

Jenkinsfile 中的 Jenkins 全局环境变量

jenkins - 如果座席离线,如何跳过一个阶段?

java - 将数据从Android插入PHP文件,然后插入Mysql错误

java - Maven onejar插件,获取属性文件

java - Scala:转换一个对象并将其分配给一个变量

java - 在 Spring 中解析 HTML 页面的问题 - Java

java-maven-idea : including external library in jar

jenkins - 如果经过验证和批准,则自动提交评论

java - 使用字符串的 equals() 返回 true,而两个变量则不返回 true

java - 无法创建 AndroidViewModel 子类的实例