Maven Compilation Error: Use -source 7 or higher to enable diamond operator

This error happens only in Maven command line compile or in your IDE if you use new features of JDK that is not available outside 1.5. The reason is that MAVEN compiler default for source and target is 1.5 JDK version. Therefore, if you are getting the following error, you can fix it two ways.

Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.2:compile (default-compile) on project StandardAppServices: Compilation failure
[ERROR] kafka/KafkaPublisher.java:[43,71] diamond operator is not supported in -source 1.5
[ERROR] (use -source 7 or higher to enable diamond operator)
[ERROR] -> [Help 1]

Resolution

  1. Fix using the build plugin
  2. <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>3.1</version>
        <configuration>
            <surce>1.7</source>
            <target>1.7</target>
        </configuration>
    </plugin>
    

  3. Fix using the Properties
  4. 	<properties>
    		<maven.compiler.source>1.8</maven.compiler.source>
    		<maven.compiler.target>1.8</maven.compiler.target>
    	</properties>