IDEA多Module的Language Level的問題

最近做了IDEA的多模塊測試項目,IDE是Intellij IDEA。發現無論是Project還是Module,默認的Language Level都是JDK 1.5,而且每次修改都僅限於當前有效,稍後又會變回JDK 1.5。刷新maven或者是重啓後,都會變成JDK 1.5。修改 java Compiler都不行。

解決辦法都是這pom.xml中指定compiler的版本,如下:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.lcc</groupId>
    <artifactId>AllTest</artifactId>
    <packaging>pom</packaging>
    <version>1.0-SNAPSHOT</version>
    <modules>
        <module>hadoop_test</module>
        <module>jdk_test</module>
        <module>druid_test</module>
        <module>concurrent_test</module>
        <module>netty_test</module>
        <module>flink_test</module>
        <module>spark_test</module>
        <module>java_test</module>
        <module>hive_test</module>
        <module>hive_1_x_parse_sql</module>
    </modules>


    <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>

</project>

直接在父級模塊加入這樣的plugin就好了。
還有簡潔版本:

<properties>
  <maven.compiler.source>1.8</maven.compiler.source>
  <maven.compiler.target>1.8</maven.compiler.target>
</properties>

原因:
是maven compiler plugin自身問題:

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.

上面這一段的內容是:

  該插件從3.0版本開始,默認編譯器是javax.tools.JavaCompiler (前提是JDK 1.6以後);如果想使用javac,需要手動設置。

  當前(Version: 3.5.1),默認使用JDK 1.5解析和編譯源碼,與運行Maven的JDK版本無關!!!如果想修改,見鏈接。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章