Maven uses the JAVA_HOME environment variable to determine which JVM
should run Maven (Maven is itself a Java program). I recommend this as the first option because build servers like Jenkins can easily control the JVM being used to run Maven.
An alternative approach (clearer to others running your build) would
be to build in a pre-condition check into the POM, using the
enforcer plug-in. Specify a rule that the it should be compiled
using a specified Java version.
A number of options available:
Maven uses the JAVA_HOME environment variable to determine which JVM should run Maven (Maven is itself a Java program). I recommend this as the first option because build servers like Jenkins can easily control the JVM being used to run Maven.
You can tweak the settings of the compiler plugin to compile using a different JDK
An alternative approach (clearer to others running your build) would be to build in a pre-condition check into the POM, using the enforcer plug-in. Specify a rule that the it should be compiled using a specified Java version.