|
28 | 28 |
|
29 | 29 | Setting the <<<--release>>> of the Java Compiler |
30 | 30 |
|
31 | | - Starting JDK 9, the <<<javac>>> executable can accept the <<<--release>>> |
| 31 | + Starting with JDK 9, the <<<javac>>> executable can accept the <<<--release>>> |
32 | 32 | 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 |
34 | 34 | build the project against Java 8. |
35 | 35 | The <<<--release>>> option ensures that the code is compiled following the |
36 | 36 | rules of the programming language of the specified release, and that generated |
37 | 37 | 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, |
40 | 39 | the compiler will detect and generate an error when using APIs that don't exist |
41 | 40 | in previous releases of Java SE. |
42 | 41 |
|
@@ -76,67 +75,8 @@ Setting the <<<--release>>> of the Java Compiler |
76 | 75 | </project> |
77 | 76 | +----- |
78 | 77 |
|
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 |
81 | 81 | supported <<<release>>> targets include the release of the currently used JDK plus a limited number |
82 | 82 | 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 | | - |
0 commit comments