Thursday, May 18, 2017

try-with-resources is not supported in -source Or Set Compiler Source and Target

try-with-resources is not supported 
Some time we face issues while building java project with maven with error below:

  1. try-with-resources is not supported in -source 1.5 [ERROR]   (use -source 7 or higher to enable try-with-resources)
  2. diamond operator is not supported in -source 1.5[ERROR]   (use -source 7 or higher to enable diamond operator)

This problem can be resolved by providing the maven compile plugin in pom.xml.

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

Here I have given the compile Jdk 1.8 as source and target. You can specify this version as per your requirement.

Source of this information is available at maven docs.

No comments:

Post a Comment