I am working in an enviroment with applications using different Java versions: 7, 8 and later.
The developers have thus installed several JDKs and each Maven pom.xml has indeed the correct <source> and <target> tags. However, sometimes the developers unadvertedly compile using a higher JDK. So they may include a Java 8 class like java.time.LocalDate in a Java 7 which will compile because it is able to resolve the import when compiling. But when the application is later moved to run on a JRE 7 it will fail because it is unable to find the Java 8 class.
It is possible to create a profile in the pom.xml like:
<profile>
<id>compiler</id>
<properties>
<JAVA_1_4_HOME>C:\Program Files\Java\j2sdk1.4.2_09</JAVA_1_4_HOME>
</properties>
</profile>
However, the location of the JDK varies per developer and I want a pom.xml which is common for everybody.
So the question is, how to enforce Maven to use a given JDK version? Not only the <source> and <target> but the JDK itself and in a generic way not tied to any given computer.