最近我将 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/