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
<properties> <java.version>1.8</java.version> </properties>
Setting Java Version Using Compiler Plugin
The Maven compiler plugin provides two options: specifying source and target versions or using the "release" argument.
<plugins> <plugin> <artifactId>maven-compiler-plugin</artifactId> <configuration> <source>1.8</source> <target>1.8</target> </configuration> </plugin> </plugins>
This is equivalent to using the following properties:
<properties> <maven.compiler.source>1.8</maven.compiler.source> <maven.compiler.target>1.8</maven.compiler.target> </properties>
From Maven 3.6 onwards, the release argument can be used to specify the Java version:
<properties> <maven.compiler.release>9</maven.compiler.release> </properties>
Differences
Best Practice
For Java 8 and below:
For Java 9 and above:
fork, executable, and JAVA_HOME
以上是如何在 Maven 中為子模組指定 Java 版本:屬性與編譯器插件?的詳細內容。更多資訊請關注PHP中文網其他相關文章!