说明:
The correct fix for the user is to replace "-source 8 -target 8" with "-release 8", which will cause javac to compile against the right set of class signatures, and will successfully compile the example program
Starting JDK 9, the javac executable can accept the --release option to specify against which Java SE release you want to build the project. For example, you have JDK 11 installed and used by Maven, but you want to build the project against Java 8. The --release option ensures that the code is compiled following the rules of the programming language of the specified release, and that generated classes target the release as well as the public API of that release. This means that, unlike the -source and -target options, the compiler will detect and generate an error when using APIs that don't exist in previous releases of Java SE.
简单的翻译下,就是你的maven-plugin的maven target和source 写成8,然后maven 运行的时候用release=8
mvn命令:
mvn clean install -Dmaven.test.failure.ignore=true -Dmaven.test.skip=true -Dmaven.compiler.release=8
pom
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
<configuration>
<source>8</source>
<target>8</target>
<encoding>${project.build.sourceEncoding}</encoding>
</configuration>
</plugin>
Java编译配置
本文介绍如何使用Maven正确配置Java项目的编译目标版本为Java 8,通过设置正确的--release选项来确保代码遵循指定版本的编程规则,并避免使用了新版本特有的API导致的编译错误。

被折叠的 条评论
为什么被折叠?



