When running our Maven build, a member of my team gets a NoSuchMethodError in one of the dependant plug-ins when executing. However, when we run java -version
from her command line, it indicates Java 1.6.0_26. The error obviously seems to be screaming that Maven is using Java 5.
How do I figure out and change what version of Java is being used by Maven?
3 potentially important notes:
Before moving on, we can check the default JDK version of Maven. Running the mvn -v command will show the Java version in which Maven runs.
You can set the JAVA_HOME parameter just before you start maven (and change it back afterwards if need be). You could also go into your mvn (non-windows)/ mvn. bat / mvn. cmd (windows) and set your java version explicitly there.
mvn -version
will output which java it's using. If JAVA_HOME is set to a valid JDK directory and Maven is using something else, then most likely someone has tampered with the way that Maven starts up.
You will need to configure maven-compiler-plugin
to use 1.6 source
and target
parameters ( by default it is 1.5 ).
This is the best done in your project's parent pom in <pluginManagment>
section ( but you can always configure it per individual projects of course ).
<build> <pluginManagement> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>2.3.2</version> <configuration> <source>1.6</source> <target>1.6</target> </configuration> </plugin> </plugins> </pluginManagement> </build>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With