Skip to content

Commit 0706b69

Browse files
committed
build: use JDK 17 to run Gradle; compile/test with JDK 11
- Decouple JDK to run Gradle from the JDK used to compile/test. - Use Java toolchains to select JDK 11 for compilation. - Set javac --release 11 for consistent API/bytecode. - Launch Test tasks with the JDK 11 toolchain. - Keep sourceCompatibility for IDEs; omit targetCompatibility.
1 parent 4b7cb01 commit 0706b69

File tree

3 files changed

+37
-18
lines changed

3 files changed

+37
-18
lines changed

.github/workflows/validate.yml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,14 +69,22 @@ jobs:
6969
uses: actions/checkout@v5 # https://github.com/actions/checkout
7070

7171

72-
- name: "Install: JDK 11 ☕"
72+
- name: "Install: JDK 11 ☕ for compilation/tests"
7373
uses: actions/setup-java@v5 # https://github.com/actions/setup-java
7474
with:
7575
distribution: temurin
7676
java-version: 11
7777
cache: gradle
7878

7979

80+
- name: "Install: JDK 17 ☕ for running gradle"
81+
uses: actions/setup-java@v5 # https://github.com/actions/setup-java
82+
with:
83+
distribution: temurin
84+
java-version: 17
85+
cache: gradle
86+
87+
8088
- name: Build with Gradle 🏗️
8189
run: ./gradlew build
8290

gradle/java-compiler-settings.gradle

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,24 @@
11
/******************************************************************************
22
* Copyright (c) 2016 TypeFox and others.
3-
*
3+
*
44
* This program and the accompanying materials are made available under the
55
* terms of the Eclipse Public License v. 2.0 which is available at
66
* http://www.eclipse.org/legal/epl-2.0,
77
* or the Eclipse Distribution License v. 1.0 which is available at
88
* http://www.eclipse.org/org/documents/edl-v10.php.
9-
*
9+
*
1010
* SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause
1111
******************************************************************************/
1212

13+
final int JAVA_VERSION = (findProperty('javaVersion') ?: 11) as Integer
14+
1315
java {
14-
sourceCompatibility = JavaVersion.VERSION_11
16+
// Keep source level at Java 11
17+
sourceCompatibility = JavaVersion.toVersion(JAVA_VERSION)
18+
// Use a Java 11 toolchain for compilation and task launches
19+
toolchain {
20+
languageVersion = JavaLanguageVersion.of(JAVA_VERSION)
21+
}
1522
}
1623

1724
tasks.withType(Javadoc) {
@@ -21,6 +28,15 @@ tasks.withType(Javadoc) {
2128

2229
tasks.withType(JavaCompile) {
2330
options.encoding = 'UTF-8'
31+
// Ensure cross-compilation targets Java 11 APIs
32+
options.release = JAVA_VERSION
33+
}
34+
35+
// Ensure tests run on the Java 11 toolchain (not the Gradle JVM)
36+
tasks.withType(Test).configureEach {
37+
javaLauncher = javaToolchains.launcherFor {
38+
languageVersion = JavaLanguageVersion.of(JAVA_VERSION)
39+
}
2440
}
2541

2642
task sourcesJar(type: Jar, dependsOn: classes) {
@@ -37,15 +53,15 @@ task javadocJar(type: Jar, dependsOn: javadoc) {
3753
from javadoc.destinationDir
3854
}
3955

40-
ext.signMethod = { jarfile ->
56+
ext.signMethod = { jarfile ->
4157
println "Signing $jarfile"
4258
def SIGNING_SERVICE = 'https://cbi.eclipse.org/jarsigner/sign'
4359
def STDOUT_FORMAT = ' %{size_upload} bytes uploaded, %{size_download} bytes downloaded (%{time_total} s)\\n'
4460

45-
ProcessBuilder curl_pb = new ProcessBuilder("curl",
61+
ProcessBuilder curl_pb = new ProcessBuilder("curl",
4662
"--fail", "--silent", "--show-error", "--output",
4763
"${jarfile}-signed", "--form", "file=@${jarfile}",
48-
"--write-out", STDOUT_FORMAT,
64+
"--write-out", STDOUT_FORMAT,
4965
SIGNING_SERVICE);
5066
println String.join(" ", curl_pb.command());
5167
curl_pb.directory(new File("${project.buildDir}"));
@@ -56,23 +72,23 @@ ext.signMethod = { jarfile ->
5672
println curl_process.text
5773

5874
if (curl_process.exitValue() != 0) {
59-
throw new GradleException("Failed to run curl");
75+
throw new GradleException("Failed to run curl");
6076
}
6177

62-
ProcessBuilder mv_pb = new ProcessBuilder("mv",
78+
ProcessBuilder mv_pb = new ProcessBuilder("mv",
6379
"${jarfile}-signed", jarfile)
6480
println String.join(" ", mv_pb.command());
6581
mv_pb.directory(new File("${project.buildDir}"));
6682
Process mv_process = mv_pb.start()
6783
mv_process.waitFor()
6884

6985
if (curl_process.exitValue() != 0) {
70-
throw new GradleException("Failed to run mv");
86+
throw new GradleException("Failed to run mv");
7187
}
7288
}
7389

7490
task signJar(description: 'Sign JARs with Eclipse Signing Service', group: 'Build'){
75-
doLast {
91+
doLast {
7692
signMethod("${project.buildDir}/libs/${project.name}-${project.version}.jar")
7793
signMethod("${project.buildDir}/libs/${project.name}-${project.version}-sources.jar")
7894
signMethod("${project.buildDir}/libs/${project.name}-${project.version}-javadoc.jar")

org.eclipse.lsp4j/build.gradle

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,18 @@
11
/******************************************************************************
22
* Copyright (c) 2016 TypeFox and others.
3-
*
3+
*
44
* This program and the accompanying materials are made available under the
55
* terms of the Eclipse Public License v. 2.0 which is available at
66
* http://www.eclipse.org/legal/epl-2.0,
77
* or the Eclipse Distribution License v. 1.0 which is available at
88
* http://www.eclipse.org/org/documents/edl-v10.php.
9-
*
9+
*
1010
* SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause
1111
******************************************************************************/
1212

1313
ext.title = 'LSP4J'
1414
description = 'Java bindings for the Language Server Protocol'
1515

16-
java {
17-
sourceCompatibility = JavaVersion.VERSION_11
18-
targetCompatibility = JavaVersion.VERSION_11
19-
}
20-
2116
dependencies {
2217
compileOnly project(":org.eclipse.lsp4j.generator")
2318
api project(":org.eclipse.lsp4j.jsonrpc")

0 commit comments

Comments
 (0)