I downloaded a Github project my team will be doing development work for (it's private, so sharing it wouldn't help). It includes a pom.xml file with the following dependency:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
<showDeprecation>true</showDeprecation>
<showWarnings>true</showWarnings>
</configuration>
</plugin>
This project depends on having Java 7. Researching this issue in other people's cases- it looks like their versions are inconsistent between java and mvn, and the JAVA_HOME environmental variable, so let me show you some Terminal output:
Last login: Thu Jun 5 13:05:34 on console
$ echo $JAVA_HOME
/Library/Java/JavaVirtualMachines/jdk1.7.0_60.jdk/Contents/Home
$ mvn -version
Apache Maven 3.2.1 (ea8b2b07643dbb1b84b6d16e1f08391b666bc1e9; 2014-02-14T12:37:52-05:00)
Maven home: /usr/local/apache-maven-3.2.1
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", arch: "x86_64", family: "mac"
$ 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)
$ javac -version
javac 1.7.0_60
It looks like Java 7 is successfully installed on my Mac, the environmental variable for JAVA_HOME is correctly set, and maven claims to have the Java version I need.
Within top level directory of that project I cloned from Github, which I will just call "githubproject", I run:
sudo mvn clean install
It runs, with good output for a while... until this:
[INFO] Compiling 239 source files to /usr/local/gardens/githubproject/target/classes
[INFO] -------------------------------------------------------------
[ERROR] COMPILATION ERROR :
[INFO] -------------------------------------------------------------
[ERROR] Failure executing javac, but could not parse the error:
javac: invalid target release: 1.7
Usage: javac <options> <source files>
use -help for a list of possible options
[INFO] 1 error
[INFO] -------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 18.793 s
[INFO] Finished at: 2014-06-05T13:08:38-05:00
[INFO] Final Memory: 26M/123M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:2.3.2:compile (default-compile) on project hgtvgardens: Compilation failure
[ERROR] Failure executing javac, but could not parse the error:
[ERROR] javac: invalid target release: 1.7
[ERROR] Usage: javac <options> <source files>
[ERROR] use -help for a list of possible options
[ERROR] -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException
So here is an interesting thing is that if I go into that pom.xml file- I can change the dependency from 1.7 to 1.6, and the mvn clean install command runs just fine- build success... However, the project has all sorts of Java errors where Java 7 was required to compile certain parts (though other parts of the project still work).
My best guess is that it's an environmental issue- but why is there an issue, and where could it be?
In researching, other people have solved their problem by copying tools.jar into /Library/Java/Extensions/ ... which I did- but to no result.
Why doesn't installing Java for Mac take care of these issues, since I haven't done much to customize Java settings outside of setting JAVA_HOME in ~/.bash_profile
Is there a system link I need to change?
Link Update
One of my team members ran
sudo rm /System/Library/Frameworks/JavaVM.framework/Versions/CurrentJDK
sudo ln -s /Library/Java/JavaVirtualMachines/jdk1.7.0_60.jdk/Contents/ /System/Library/Frameworks/JavaVM.framework/Versions/CurrentJDK
and it fixed his build error- but he is getting the same issues where it looks like the project was compiled wrong.
Other team members have no issues at all- same OS, hardware, Github project, and software... something is different- and I'm not sure what...
Mavan Compiler Plugin Update
Someone suggested using a more updated maven compiler.
Downloaded maven-compiler-plugin-3.1.jar from http://search.maven.org/#artifactdetails|org.apache.maven.plugins|maven-compiler-plugin|3.1|maven-plugin and copied it into my apache-maven/lib directory (this is a complete guess). Then I updated the pom.xml to use 3.1 instead of 2.3.2
The result:
[ERROR] Failed to execute goal
org.apache.maven.plugins:maven-compiler-plugin:3.1:compile
(default-compile) on project githubproject: Execution default-compile of goal
org.apache.maven.plugins:maven-compiler-plugin:3.1:compile failed:
A required class was missing while executing
org.apache.maven.plugins:maven-compiler-plugin:3.1:compile:
org/codehaus/plexus/compiler/util/scan/mapping/SuffixMapping
I might have done this wrong.
(My) Answer
I figured it out- the permissions weren't allowing access to the files in that githubproject. I just had to change permissions to those files and it successfully built. (Putting the compiler plugin under my mavin lib directory broke maven for a while, but I finally got rid of that ill-placed jar). Thanks to everyone who gave this attention- the error was a red herring.