I tried the maven-compiler-plugin approach and it turned out to be cumbersome as there are plugins like maven-surefire-plugin and maven-cobertura-plugin which still do not work due to incompatibility issues.
The best approach was to use the maven-toolchain-plugin .
Step 1 Create /. M2 / toolchains.xml
<?xml version="1.0" encoding="UTF8"?> <toolchains> <toolchain> <type>jdk</type> <provides> <version>1.8</version> <vendor>sun</vendor> </provides> <configuration> <jdkHome>/Library/Java/JavaVirtualMachines/jdk1.8.0_25.jdk/Contents/Home</jdkHome> </configuration> </toolchain> <toolchain> <type>jdk</type> <provides> <version>1.7</version> <vendor>sun</vendor> </provides> <configuration> <jdkHome>/Library/Java/JavaVirtualMachines/jdk1.7.0_67.jdk/Contents/Home</jdkHome> </configuration> </toolchain> <toolchain> <type>jdk</type> <provides> <version>1.6</version> <vendor>apple</vendor> </provides> <configuration> <jdkHome>/Library/Java/JavaVirtualMachines/1.6.0_65-b14-462.jdk/Contents/Home</jdkHome> </configuration> </toolchain>
Step 2 Add the maven-toolchain-plugin to the plugins in your pom.xml project.
* If you are using maven 3, make sure this also applies to pluginManagement *
<plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-toolchains-plugin</artifactId> <version>1.1</version> <executions> <execution> <goals> <goal>toolchain</goal> </goals> </execution> </executions> <configuration> <toolchains> <jdk> <version>1.7</version> <vendor>sun</vendor> </jdk> </toolchains> </configuration> </plugin>
Voila all your other plugins pick up the correct JDK . Hope it helps. Today I spent almost half a day on this exact issue.
chinto
source share