【问题标题】:Fatal error compiling: invalid flag: --release for jdk 11 on Jenkins?致命错误编译:无效标志:Jenkins 上 jdk 11 的 --release?
【发布时间】:2021-08-09 15:45:39
【问题描述】:

最近我将spring批处理项目从java 8升级到了11。

它在本地运行良好,我决定推送到 Jenkins,但出现以下错误。

Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (default-compile) on project bandwidth: 

Fatal error compiling: invalid flag: --release -> [Help 1]

应该是什么原因,我该如何解决?

旧设置:pom 中的 java 8

<properties>
    <maven.compiler.source>1.8</maven.compiler.source>
    <maven.compiler.target>1.8</maven.compiler.target>

    <org.springframework-version>3.1.1.RELEASE</org.springframework-version>
    <org.springframework.batch>2.1.9.RELEASE</org.springframework.batch>
    <org.slf4j-version>1.6.2</org.slf4j-version>
</properties>
<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-compiler-plugin</artifactId>
    <configuration>
            <source>1.7</source>
            <target>1.7</target>
            <encoding>iso-8859-1</encoding>
    </configuration>
</plugin>

新设置:pom 中的 java 11

<properties>
        <java.version>11</java.version>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>

        <org.springframework-version>3.1.1.RELEASE</org.springframework-version>
        <org.springframework.batch>2.1.9.RELEASE</org.springframework.batch>
        <org.slf4j-version>1.6.2</org.slf4j-version>
</properties>
<plugin>
     <groupId>org.apache.maven.plugins</groupId>
     <artifactId>maven-compiler-plugin</artifactId>
     <version>3.8.1</version>
     <configuration>
            <release>11</release>
            <encoding>iso-8859-1</encoding>
    </configuration>
</plugin>

【问题讨论】:

标签: java spring maven jenkins java-11


【解决方案1】:

问题在于使用默认系统 JDK 的 Jenkins 设置。

我确实添加了以下内容并更正了 Jenkins 指向 JDK 11。

<properties>
     <java.version>11</java.version>
     <maven.compiler.source>11</maven.compiler.source>
     <maven.compiler.target>11</maven.compiler.target>
 <properties>

感谢@naman 让我找到了正确的方向。

【讨论】:

  • 您确定您的 Jenkins 使用 JDK 11 运行(删除这些配置后,您可能只是回退到 Maven 解析的默认 Java 版本)?只需尝试使用-X 执行mvn 命令,然后自己查看它使用哪个Java 版本来执行Maven 命令。要使用的属性可以是&lt;maven.compiler.release&gt;11&lt;/maven.compiler.release&gt;
猜你喜欢
  • 2018-08-12
  • 2018-02-17
  • 2019-10-30
  • 2020-11-19
  • 2017-03-19
  • 1970-01-01
  • 2021-01-18
  • 2015-06-14
相关资源
最近更新 更多