我正在使用java 11使用一些依赖项和编译到旧版本.我将一个依赖项迁移到Java 11并且工作正常,但我们仍然必须在Java8上运行Tomcat 7或8.是否有可能使用--release
标志来编译它使用的代码var
,stream().dropwhile(...)
或Map.of(...)
和8上运行?
发布标志表明它应该是可能的:
--release release针对特定VM版本的公共,支持和记录的API进行编译.支持的发布目标是6,7,8和9.
这个项目是一个依赖项,独立于SprinBoot2.1和Java11可以正常工作,但需要在Java8中运行.
我的maven插件编译器设置:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
<configuration>
<release>8</release>
</configuration>
</plugin>
Run Code Online (Sandbox Code Playgroud)
但是这禁止编译> jdk8特定代码.我正在使用上面最新的maven 3.6.0和mvn编译器.
尝试编译:
return List.of("dsadas", "dasdadddds", "£dsada", "dasdas")
.stream()
.dropWhile(s -> s.contains("das"))
.collect(Collectors.toList());
Run Code Online (Sandbox Code Playgroud)
抛出错误:
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.0:compile (default-compile) on project api: Compilation failure: Compilation failure:
[ERROR] /home/agilob/Projects/.....java:[58,13] cannot find symbol
[ERROR] symbol: class var
[ERROR] location:
[ERROR] /home/agilob/Projects/....java:[43,20] cannot find symbol
[ERROR] symbol: method of(java.lang.String,java.lang.String,java.lang.String,java.lang.String)
[ERROR] location: interface java.util.List
[ERROR] -> …
Run Code Online (Sandbox Code Playgroud)