maven 的编译插件的配置

原文: https://stackoverflow.com/questions/29258141/maven-compilation-error-use-source-7-or-higher-to-enable-diamond-operator/31734791#31734791

--------------------------------------------------------------------------------------------------------

WHY IT HAPPENS

The problem arises because

[...] 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 Compiler Plugin Introduction

That's why changing the JDK has no effect on the source level. So you have a couple of way to tell Maven what source level to use.

SOLUTIONS

  • Configure the Maven compiler plugin in the pom.xml
<build>

<plugins>
    <plugin>
        <artifactId>maven-compiler-plugin</artifactId>
        <configuration>
            <source>1.7</source>
            <target>1.7</target>
        </configuration>
    </plugin>
</plugins>
...
  • OR Set these properties (always in the pom)
<properties>
<maven.compiler.source>1.7</maven.compiler.source>
<maven.compiler.target>1.7</maven.compiler.target>
</properties>

JDK VERSION TO USE?

If you set a target 1.7 like in this example be sure that the mvn command is actually launched with a jdk7 (or higher)

LANGUAGE LEVEL ON THE IDE

Usually IDEs use maven pom.xml file as a source of project configuration. Changing the compiler settings in the IDE not always has effect on the maven build. That's why, the best way to keep a project always manageable with maven (and interoperable with other IDEs) is edit the pom.xml files and instruct the IDE to sync with maven.

原文地址:https://www.cnblogs.com/oxspirt/p/8480480.html