Maven Compilation Error: (use -source 7 or higher to enable diamond operator)

HappyCoding picture HappyCoding · Mar 25, 2015 · Viewed 60.9k times · Source

I'm using maven in IntelliJ, JDK1.8, maven 3.2.5. Got compilation error: use -source 7 or higher to enable diamond opera. details are as follows:

  [ERROR] COMPILATION ERROR : 
  [INFO] -------------------------------------------------------------
  [ERROR] TrainingConstructor.java:[31,55] diamond operator is not supported in -source 1.5 (use -source 7 or higher to enable diamond operator)
  [ERROR] DTM.java:[79,21] try-with-resources is not supported in -source 1.5  (use -source 7 or higher to enable try-with-resources)
  [ERROR] ticons.java:[53,44] diamond operator is not supported in -source 1.5  (use -source 7 or higher to enable diamond operator)

Any suggestions? Is there any other configuration to set this -source level? seems it doesn't use java 1.8.

Answer

Sergey Pauk picture Sergey Pauk · Mar 25, 2015

Check how your maven-compiler-plugin is configured, it should use java version 7 or higher:

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

For a more complete answer see the one below.