Home > Java > javaTutorial > How do you specify Java version in Maven for child modules: properties vs. compiler plugin?

How do you specify Java version in Maven for child modules: properties vs. compiler plugin?

Mary-Kate Olsen
Release: 2024-11-15 09:52:03
Original
594 people have browsed it

How do you specify Java version in Maven for child modules: properties vs. compiler plugin?

Specifying Java Version in Maven: Comparing Properties and Compiler Plugin

Introduction

When working with Maven, specifying the Java version for child modules in a multi-module project requires consideration. This article examines the differences between setting Java version using Java properties and the Maven compiler plugin.

Setting Java Version Using Properties

The java.version property in the section of the pom.xml is designed for use with Spring Boot and sets both the source and target Java versions:

Setting Java Version Using Compiler Plugin

The Maven compiler plugin provides two options: specifying source and target versions or using the "release" argument.

  • Source and Target:

This is equivalent to using the following properties:

  • Release:

From Maven 3.6 onwards, the release argument can be used to specify the Java version:

Differences

  • Source and Target vs. Properties: They are functionally equivalent.
  • Release: In Maven 3.8 and above, it provides a standardized way to specify all three versions (source, target, and bootstrap) for Java 9 and later.
  • Spring Boot: java.version is only functional in Spring Boot projects.

Best Practice

For Java 8 and below:

  • Use either method to specify source and target.
  • If only source is specified, Maven may use a different target version based on the specified source.

For Java 9 and above:

  • Consider using the release argument to ensure consistent versions for source, target, and bootstrap.

fork, executable, and JAVA_HOME

  • If the JAVA_HOME JDK version is incompatible with the specified Java versions, specify fork="true" and executable in the compiler configuration.
  • It is not recommended for the source and target versions to exceed the JDK version pointed by JAVA_HOME, as the JDK cannot compile with a more recent specification.

The above is the detailed content of How do you specify Java version in Maven for child modules: properties vs. compiler plugin?. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template