默认情况下,maven不会在JVM级别编译代码。 代码级别可以使用属性传递给编译器。
<properties> <maven.compiler.target>1.8</maven.compiler.target> <maven.compiler.source>1.8</maven.compiler.source> </properties>
如果由于兼容性问题(如使用与Java 5兼容的Lambda表达式)编译器无法编译代码,则将返回以下错误:
ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (default-compile) on project project: Compilation failure [ERROR] /PATH/CLASSNAME.java:[62,29] lambda expressions are not supported in -source 1.5 [ERROR] (use -source 8 or higher to enable lambda expressions) [ERROR] -> [Help 1]