user3804769
user3804769

Reputation: 507

maven - Specify java compiler subversion

When running Maven Update, Maven changes the jdk version for my Eclipse projects. I've seen many threads here asking how to specify a Java version for Maven, and it's easy:

<properties>
   <maven.compiler.source>1.8</maven.compiler.source>
   <maven.compiler.target>1.8</maven.compiler.target>
</properties>

I have both JDK 1.8.0_181 and 1.8.0_172 installed. If I want to keep using 172 for my system but I want to use 181 to compile, how could I tell that to maven? Can I only specify the main version (1.8) and not the other minor version numbers?

Upvotes: 1

Views: 286

Answers (2)

Josh White
Josh White

Reputation: 194

You can specify path used by the maven compiler by setting the path to the javac version you want to use.

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-compiler-plugin</artifactId>
    <version>3.8.0</version>
    <configuration>
      <verbose>true</verbose>
      <fork>true</fork>
      <executable><!-- path-to-javac --></executable>
      <compilerVersion>1.3</compilerVersion>
    </configuration>
  </plugin>

You could also use a toolchain in maven. This allows you to specify the version as well as the path to the JDK used for compilation. This would allow you to point to the minor version you would like to use. To configure follow the guide from the official documentation.

Upvotes: 1

J Fabian Meier
J Fabian Meier

Reputation: 35785

The numbers you mention are not related to the actual JDK version that you use. This is usually set through JAVA_HOME. You can also explictely set it in the Maven compiler plugin

http://maven.apache.org/plugins/maven-compiler-plugin/examples/compile-using-different-jdk.html

The properties you mention set the behaviour of the compiler. You can e.g. compile with 1.7 even if using JDK 1.8.x (but not 1.8 with JDK 1.7.x).

Upvotes: 2

Related Questions