Maven: Viewing compile options?
I'm trying to track down this compile error:
$ mvn compile ... [ERROR] /.../Reader.java:[14,13] try-with-resources is not supported in -source 1.5 (use -source 7 or higher to enable try-with-resources)
How can find the -source 1.5 setting in my Maven compilation? I'm using a plain vanilla pom.xml which (as far as I can tell) isn't setting anything.
This is because you are using a plain vanilla pom.xml that you have this issue.
By default, the maven-compiler-plugin, which is called when compiling the sources, compiles with Java 5, whatever you have set up as $JAVA_HOME:
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.
To use a different compiler version (e.g. Java 8), you can set the following properties:
<properties> <maven.compiler.source>1.8</maven.compiler.source> <maven.compiler.target>1.8</maven.compiler.target> </properties>
or configure the plugin directly:
<plugin> <artifactId>maven-compiler-plugin</artifactId> <version>3.3</version> <configuration> <source>1.8</source> <target>1.8</target> </configuration> </plugin>