idea
的project structure配置
若是缺乏第三部,會出現以下錯誤java
設置完成以後,若是從新啓動IDEA時,就會發現全部的設置又從新恢復到默認狀態(JDK 1.5)web
緣由是:apache
Apache Maven Compiler Plugin
The Compiler Plugin is used to compile the sources of your project. Since 3.0, the default compiler is javax.tools.JavaCompiler (if you are using java 1.6) and is used to compile Java sources. If you want to force the plugin using javac, you must configure the plugin option forceJavacCompilerUse.
Also note that at present the default source setting is 1.5 and the default target setting is 1.5, independently of the JDK you run Maven with. If you want to change these defaults, you should set source and target as described in Setting the -source and -target of the Java Compiler.
複製代碼
解釋是:maven
該插件從3.0版本開始,
默認編譯器是javax.tools.JavaCompiler (前提是JDK 1.6之後);
若是想使用javac,須要手動設置。
當前(Version: 3.5.1),
默認使用JDK 1.5解析和編譯源碼,
與運行Maven的JDK版本無關!
複製代碼
PS:ide
<project>
[...]
<build>
[...]
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.5.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
[...]
</build>
[...]
</project>
複製代碼
pom.xml中指定compiler的版本ui
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
複製代碼
固然還有一個簡單寫法idea
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
複製代碼