Skip to content

Instantly share code, notes, and snippets.

@shui
Last active September 25, 2017 01:17
Show Gist options
  • Save shui/922e39d7d30d6816a7f480dea1be5d5f to your computer and use it in GitHub Desktop.
Save shui/922e39d7d30d6816a7f480dea1be5d5f to your computer and use it in GitHub Desktop.
Warning:java: 源值1.5已过时, 将在未来所有发行版中删除

pom.xml 加入如下代码。

<project>
  [...]
  <properties>
    <maven.compiler.release>9</maven.compiler.release>
    <maven.compiler.source>1.9</maven.compiler.source>
    <maven.compiler.target>1.9</maven.compiler.target>
  </properties>
  [...]
</project>

参考Setting the -source and -target of the Java Compiler如何在Maven项目中设置Java 9

从JDK 9 b72开始,有个新功能将成为可用:javac –release命令行选项。简而言之,要使用javac交叉编译到较旧版本的平台,将设置-source和-target选项设置为较旧的值是不够的; 在bootclasspath也必须设置对应于旧版本了。设置bootclasspath经常被遗忘并获取所需的信息可能不方便。

该--release标志着javac解决了这两个缺点。在交叉编译时仅需要设置单个标志,相比以前需要设置三个标志(source,-target,-bootclasspath)和这样所需要的信息都被包括在JDK。接受的参数值为--release6,7,8和9。

属性 maven.compiler.release直接映射到该--release标志javac,而另外两个属性只对IntelliJ有必要 ,用来了解源码兼容性。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment