Maven in OSX Keeps Compiling with Java 1.5

316 views Asked by At

I have a code that I'm working on from 2 different location, a Win7 machine and an OSX.

When worked on using Win7 machine, I don't need to bother about which java version that Maven compiles, I just need to set the PATH variable. If I'm on Java 5, it compiles against Java 5, if I'm on Java 7, it compiles against Java 7. No problem there.

Different case for my OSX machine. Now this is the exact same set of codes.

My Java version

[Mac-Pro] ~/apache-maven/apache-maven-3.1.1/conf $
p01ntbl4nk> java -version
java version "1.7.0_60"
Java(TM) SE Runtime Environment (build 1.7.0_60-b19)
Java HotSpot(TM) 64-Bit Server VM (build 24.60-b09, mixed mode)

My Maven version

[Mac-Pro] ~/apache-maven/apache-maven-3.1.1/conf $
p01ntbl4nk> mvn -version
Apache Maven 3.1.1 (0728685237757ffbf44136acec0402957f723d9a; 2013-09-17 23:22:22+0800)
Maven home: /Users/p01ntbl4nk/apache-maven/apache-maven-default
Java version: 1.7.0_60, vendor: Oracle Corporation
Java home: /Library/Java/JavaVirtualMachines/jdk1.7.0_60.jdk/Contents/Home/jre
Default locale: en_US, platform encoding: UTF-8
OS name: "mac os x", version: "10.9.1", arch: "x86_64", family: "mac"

Both shows the same java version. Java 7u60.

But when I run mvn clean compile on my codes, I am getting this "try-with-resource is not supported in -source1.5"

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:2.5.1:compile (default-compile) on project archival-client: Compilation failure
[ERROR] /Users/p01ntbl4nk/GitRepositories/GenericArchival/root/archival-client/src/main/java/org/si/genericArchival/client/App.java:[140,6] error: try-with-resources is not supported in -source 1.5
[ERROR] -> [Help 1]
[ERROR] 

I've checked, I don't have any reference in my main maven settings.xml or in any of the pom.xml in the modules that would indicate to use sourve version 1.5

To fix this, I would have to add the following to all my pom.xml

<plugin>
    <artifactId>maven-compiler-plugin</artifactId>
    <version>3.1</version>
    <configuration>
        <source>1.7</source>
        <target>1.7</target>
    </configuration>
</plugin>

But this would mean that the maven modules are no longer adaptable to the java version of the underlying platform.

Am I missing anything?

1

There are 1 answers

4
doog abides On

Well, you already have your answer, but here it is definitively. http://maven.apache.org/plugins/maven-compiler-plugin/

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. 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.