Skip to content

Commit f79c7fd

Browse files
authored
Update docs for Maven 4 and release option
1 parent 9337c3c commit f79c7fd

File tree

4 files changed

+30
-81
lines changed

4 files changed

+30
-81
lines changed

src/site/apt/examples/set-compiler-release.apt.vm

Lines changed: 6 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,14 @@
2828

2929
Setting the <<<--release>>> of the Java Compiler
3030

31-
Starting JDK 9, the <<<javac>>> executable can accept the <<<--release>>>
31+
Starting with JDK 9, the <<<javac>>> executable can accept the <<<--release>>>
3232
option to specify against which Java SE release you want to build the project.
33-
For example, you have JDK 11 installed and used by Maven, but you want to
33+
For example, you have JDK 17 installed and used by Maven, but you want to
3434
build the project against Java 8.
3535
The <<<--release>>> option ensures that the code is compiled following the
3636
rules of the programming language of the specified release, and that generated
3737
classes target the release as well as the public API of that release. This
38-
means that, unlike the
39-
{{{../examples/set-compiler-source-and-target.html}<<<-source>>> and <<<-target>>> options}},
38+
means that, unlike the old <<<-source>>> and <<<-target>>> options,
4039
the compiler will detect and generate an error when using APIs that don't exist
4140
in previous releases of Java SE.
4241

@@ -76,67 +75,8 @@ Setting the <<<--release>>> of the Java Compiler
7675
</project>
7776
+-----
7877

79-
<<Note:>> The value in the <<<release>>> parameter follows the new version naming scheme adopted
80-
since Java 9. As such, the release number does not start with 1.x anymore. Also note that the
78+
<<Note:>> The value in the <<<release>>> parameter follows
79+
{{{https://openjdk.org/jeps/223}Java's new Version-String Scheme (JEP 223)}}} adopted since Java 9.
80+
As such, the release number does not start with 1.x anymore. Also note that the
8181
supported <<<release>>> targets include the release of the currently used JDK plus a limited number
8282
of previous releases.
83-
84-
* Usage on JDK 8
85-
86-
The <<<--release>>> option is not supported using JDK 8. To enable a project that targets Java 8
87-
to be built using JDK 8 and also JDK 9 or later requires the conditional usage of the
88-
<<<--release>>> option.
89-
90-
Conditional parametrization is required for the Compiler Plugin version below <<<3.13.0>>>
91-
or compilerId different that <<<javac>>>.
92-
93-
This may be done through the use of a profile:
94-
95-
+-----
96-
<project>
97-
[...]
98-
<profiles>
99-
[...]
100-
<profile>
101-
<id>set-compiler-release</id>
102-
<activation>
103-
<jdk>[9,)</jdk>
104-
</activation>
105-
<properties>
106-
<maven.compiler.release>8</maven.compiler.release>
107-
</properties>
108-
</profile>
109-
[...]
110-
</profiles>
111-
[...]
112-
</project>
113-
+-----
114-
115-
Since version <<<3.13.0>>> of the Compiler Plugin together with the default <<<javac>>> compilerId you don't need conditional parametrisation of <<<release>>>.
116-
The <<<release>>> parameter will only be effective for Java 9 or above, otherwise the <<<source>>> and <<<target>>> will be passed to the compiler.
117-
118-
So you can simply configure as:
119-
120-
+-----
121-
<project>
122-
[...]
123-
<build>
124-
[...]
125-
<plugins>
126-
<plugin>
127-
<groupId>org.apache.maven.plugins</groupId>
128-
<artifactId>maven-compiler-plugin</artifactId>
129-
<version>${project.version}</version>
130-
<configuration>
131-
<release>8</release>
132-
<source>8</source>
133-
<target>8</target>
134-
</configuration>
135-
</plugin>
136-
</plugins>
137-
[...]
138-
</build>
139-
[...]
140-
</project>
141-
+-----
142-

src/site/apt/examples/set-compiler-source-and-target.apt.vm

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,21 +28,25 @@
2828

2929
Setting the <<<-source>>> and <<<-target>>> of the Java Compiler
3030

31+
(If you're are using version <<<3.13.0>>> or newer of the Compiler Plugin, use the recommended
32+
{{{../examples/set-compiler-release.html}<<<maven.compiler.release>>> property}}.)
33+
3134
Sometimes when you may need to compile a certain project to a different
3235
version than what you are currently using. The <<<javac>>> can accept
3336
such command using <<<-source>>> and <<<-target>>>. The Compiler Plugin
3437
can also be configured to provide these options during compilation.
38+
You have to set the version following {{{https://openjdk.org/jeps/223}Java's new Version-String Scheme (JEP 223)}}}.
3539

36-
For example, if you want to use the Java 8 language features (<<<-source 1.8>>>)
37-
and also want the compiled classes to be compatible with JVM 1.8 (<<<-target 1.8>>>),
38-
you can either add the two following properties, which are the default property names for the plugin parameters:
40+
For example, if you want to use the Java 8 language features and also want the compiled classes to be compatible
41+
with JVM 8 (former 1.8) you can either add the two following properties, which are the default property names
42+
for the plugin parameters:
3943

4044
+-----
4145
<project>
4246
[...]
4347
<properties>
44-
<maven.compiler.source>1.8</maven.compiler.source>
45-
<maven.compiler.target>1.8</maven.compiler.target>
48+
<maven.compiler.source>8</maven.compiler.source>
49+
<maven.compiler.target>8</maven.compiler.target>
4650
</properties>
4751
[...]
4852
</project>
@@ -61,8 +65,8 @@ Setting the <<<-source>>> and <<<-target>>> of the Java Compiler
6165
<artifactId>maven-compiler-plugin</artifactId>
6266
<version>${project.version}</version>
6367
<configuration>
64-
<source>1.8</source>
65-
<target>1.8</target>
68+
<source>8</source>
69+
<target>8</target>
6670
</configuration>
6771
</plugin>
6872
</plugins>
@@ -79,6 +83,9 @@ Setting the <<<-source>>> and <<<-target>>> of the Java Compiler
7983
{{{http://www.mojohaus.org/animal-sniffer/animal-sniffer-maven-plugin/}Animal Sniffer Maven Plugin}}
8084
to verify your code doesn't use unintended APIs, or better yet use the
8185
{{{../examples/set-compiler-release.html}<<<release>>> option supported since JDK 9}}.
86+
Since plugin version <<<3.13.0>>> you can use the <<<release>>> property also on JDK 8.
87+
The compiler plugin will convert it to <<<source>>> and <<<target>>> automatically.
88+
8289
In the same way, setting the <<<source>>> option does not guarantee that your code actually compiles on a JDK with
8390
the specified version. To compile your code with a specific JDK version, different than the one used to launch Maven,
8491
refer to the {{{../examples/compile-using-different-jdk.html}Compile Using A Different JDK}} example.

src/site/apt/index.apt.vm

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,13 @@
2929
${project.name}
3030

3131
The Compiler Plugin is used to compile the sources of your project. The
32-
default compiler used to compile Java sources is javax.tools.JavaCompiler.
33-
Other compilers than <<<javac>>> can be used.
32+
default compiler used to compile Java sources is <<<javac>>>.
33+
If you want to use another compiler, refer to the {{{./non-javac-compilers.html} guide: Using Non-Javac Compilers}}.
34+
35+
At present the default <<<source>>> and the default <<<target>>>
36+
setting are both <<<8>>>, independently of the JDK you run Maven with.
37+
You are highly encouraged to change these defaults by setting the <<<release>>> option as described in the
38+
{{{./examples/set-compiler-release.html}guide: Compile Using The <<<--release>>> javac Option}}.
3439

3540
<<NOTE:>> <To know more about the JDK javac, please see:
3641
{{https://docs.oracle.com/en/java/javase/17/docs/specs/man/javac.html}}.>
@@ -70,11 +75,9 @@ ${project.name}
7075
To provide you with better understanding on some usages of the Compiler
7176
Plugin, you can take a look into the following examples:
7277

73-
* {{{./examples/compile-using-different-jdk.html}Compile Using A Different JDK}}
74-
75-
* {{{./examples/set-compiler-source-and-target.html}Compile Using -source and -target javac Options}}
78+
* {{{./examples/compile-using-different-jdk.html}Compile using A Different JDK}}
7679

77-
* {{{./examples/set-compiler-release.html}Compile Using the --release javac Option (supported since JDK 9)}}
80+
* {{{./examples/set-compiler-release.html}Compile Using The --release javac Option}}
7881

7982
* {{{./examples/compile-with-memory-enhancements.html}Compile Using Memory Allocation Enhancement}}
8083

src/site/site.xml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,7 @@ under the License.
3434
</menu>
3535
<menu name="Examples">
3636
<item name="Compile Using A Different JDK" href="examples/compile-using-different-jdk.html"/>
37-
<item name="Compile Using -source and -target javac Options" href="examples/set-compiler-source-and-target.html"/>
38-
<item name="Compile Using the --release javac Option (JDK 9+)" href="examples/set-compiler-release.html"/>
37+
<item name="Compile Using the --release javac Option" href="examples/set-compiler-release.html"/>
3938
<item name="Compile Using Memory Allocation Enhancements" href="examples/compile-with-memory-enhancements.html"/>
4039
<item name="Pass Compiler Arguments" href="examples/pass-compiler-arguments.html"/>
4140
<item name="Non-javac compilerIds" href="non-javac-compilers.html"/>

0 commit comments

Comments
 (0)