You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
baseline-java-versions: javaCompiler property to compile Java code with a certain JDK version (#3342)
baseline-java-versions: Introduce an optional javaCompiler property to javaVersions which will determine which JDK is used to run the Java compiler. In this mode, --release is now used to target lower Java language versions/class file bytecode than the compiler.
Copy file name to clipboardExpand all lines: README.md
+6-9Lines changed: 6 additions & 9 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -21,7 +21,6 @@ _Baseline is a family of Gradle plugins for configuring Java projects with sensi
21
21
| `com.palantir.baseline-reproducibility` | Sensible defaults to ensure Jar, Tar and Zip tasks can be reproduced
22
22
| `com.palantir.baseline-exact-dependencies` | Ensures projects explicitly declare all the dependencies they rely on, no more and no less
23
23
| `com.palantir.baseline-encoding` | Ensures projects use the UTF-8 encoding in compile tasks.
24
-
| `com.palantir.baseline-release-compatibility` | Ensures projects targeting older JREs only compile against classes and methods available in those JREs.
25
24
| `com.palantir.baseline-testing` | Configures test tasks to dump heap dumps (hprof files) for convenient debugging
26
25
| `com.palantir.baseline-test-heap` | Increases the default Test task heap from 512m to 2g.
27
26
| `com.palantir.baseline-java-compiler-diagnostics` | Applies the `-Xmaxwarns` and `-Xmaxwarns` compiler options with a very large limit to avoid truncating failure info.
@@ -242,12 +241,6 @@ checkImplicitDependencies {
242
241
243
242
This plugin sets the encoding for JavaCompile tasks to `UTF-8`.
244
243
245
-
## com.palantir.baseline-release-compatibility
246
-
247
-
This plugin adds the `--release <number>` flag to JavaCompile tasks (when the compiler [supports it](https://openjdk.java.net/jeps/247)), so that published jars will only use methods available in the target JRE. Relying on `sourceCompatibility = 1.8` and `targetCompatibility = 1.8` is insufficient because you run the risk of using method that have been added in newer JREs, e.g. `Optional#isEmpty`.
248
-
249
-
This plugin may become redundant if this functionality is implemented upstream [in Gradle](https://github.com/gradle/gradle/issues/2510).
250
-
251
244
## com.palantir.baseline-testing
252
245
253
246
Configures some sensible defaults:
@@ -289,15 +282,17 @@ The plugin is currently used on an opt-in basis. To use it, apply the plugin and
The configurable fields of the `javaVersions` extension are:
299
-
*`libraryTarget`: (required) The Java version used for compilation of libraries that are published.
300
-
*`distributionTarget`: (optional) The Java version used for compilation of code used within distributions, but not published externally. Defaults to the `libraryTarget` version.
293
+
*`javaCompiler`: (optional) The version of the Java compiler used. If not set, the appropriate `target` will be used. The `--release`, `--target` and `--source` compiler args are used to enable compiling code at a lower target than the compiler used. However, if `baseline-module-jvm-args`/`moduleJvmArgs` are used, `--release` will not be set as it is not compatible with exporting/opening system modules, meaning compilation will not fail if JDK APIs are used which are higher than the requested target.
294
+
*`libraryTarget`: (required) The Java version targeted for compilation of libraries that are published.
295
+
*`distributionTarget`: (optional) The Java version targeted for compilation of code used within distributions, but not published externally. Defaults to the `libraryTarget` version.
301
296
*`runtime`: (optional) Runtime Java version for testing and packaging distributions. Defaults to the `distributionTarget` version.
302
297
303
298
The configured Java versions are used as defaults for all projects.
@@ -326,12 +321,14 @@ A sub-project can also explicitly override the default Java versions, but doing
326
321
```gradle
327
322
// In a sub-project's build.gradle
328
323
javaVersion {
324
+
javaCompiler = 17
329
325
target = 11
330
326
runtime = 11
331
327
}
332
328
```
333
329
334
330
The optionally configurable fields of the `javaVersion` extension are:
331
+
*`javaCompiler`: The version of the Java compiler used. If not set, `target` will be used. See note in above `javaVersions` extension regarding `javaCompiler`.
335
332
*`target`: The target version used for compilation.
336
333
*`runtime`: The runtime version used for testing and distributions.
0 commit comments