java - 编译 fatal error : invalid flag: --release for jdk 11 on Jenkins?

标签 java spring maven jenkins java-11

最近我将 spring Batch 项目从 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>

最佳答案

问题出在 Jenkins 设置上,该设置会回退到默认系统 JDK。

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

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

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

关于java - 编译 fatal error : invalid flag: --release for jdk 11 on Jenkins?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67619516/

相关文章:

java - 面对日历对象的问题

java - 如何使用 SpEL 来评估子对象可能为空的子对象属性

java - 我可以将单个静态项目注入(inject) Spring Batch 项目读取器吗?

maven - 当 docker-maven 插件尝试构建镜像时会发生什么?

java - 如何覆盖 Spring Boot 库属性?

java - 什么?android :attr/listPreferredItemHeight is doing and how?

java - 除了 Jackson 之外,还有其他东西可以在 Java 中处理复杂的对象吗?

linux - 无法通过 http ://localhost:9000 with Sonarqube-4. 5.1 访问 SonarQube 服务器

Android for Maven Eclipse 插件无法安装

java - 尝试使用 Hashmap<Integer, Integer>