IntelliJ Idea編譯報錯:請使用 -source 7 或更高版本以啟用 diamond 運算子

水桶前輩發表於2018-11-21

IntelliJ Idea maven專案編譯報錯:


Information:Using javac 1.7.0_79 to compile java sources
Information:java: javacTask: 源發行版 1.7 需要目標發行版 1.7
Information:java: Errors occurred while compiling module 'wsdlutils'
Information:2016/4/13 16:42 - Compilation completed with 1 error and 0 warnings in 1s 805ms
Error:java: Compilation failed: internal java compiler error
參考文章[http://blog.csdn.net/wave_1102/article/details/47671019]都不能解決問題。

原來在IntelliJ Idea 預設的jdk是1.5。以上的修改都不會起作用的。見【https://maven.apache.org/plugins/maven-compiler-plugin/】

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.


在專案的pom檔案中加以下內容:

 <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <source>1.7</source>
                    <target>1.7</target>
                </configuration>
            </plugin>
        </plugins>
    </build>


 

相關文章