I have a Maven aggregator project (i.e. a project with modules) which I want to build in Eclipse using "Run As -> Maven install". My problem is that the project requires JDK 1.6, while Eclipse uses JDK 1.7 (the default JRE) to run Maven in. This problem only occurs when building the aggregator ("parent") project, not when building the modules separately.
I have tried to set the source and target properties in the POM, both like this:
<properties>
<maven.compiler.source>1.6</maven.compiler.source>
<maven.compiler.target>1.6</maven.compiler.target>
</properties>
and like this:
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
but neither worked.
I guess the problem is the following: For "normal" Maven projects, Eclipse uses the build path JRE (which is determined by the POM settings) to decide which JRE to run Maven in. Now for an aggregator project, which has a packaging type of "pom", there is no Eclipse build path and therefore Eclipse fails to choose the "right" JRE.
Does anybody know how to solve this problem? Ideally, the solution would only involve changing the POM and not the project or global Eclipse settings.
Open the "Run Configurations" editor. There is a category "Maven Build". Create a new configuration in there. That will give you a JRE tab on the right side of the dialog. Select whatever JRE you want in there.
You can save this launch config in the project using the "Share file" option in the tab "Common".
You may also want to check the Maven enforcer plugin, especially requireJavaVersion. That allows you to add checks to the build that fail when the wrong JRE is used.