Skip to content

Commit 3e289b0

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 3e289b0

File tree

6 files changed

+40
-11
lines changed

6 files changed

+40
-11
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.properties

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
org.gradle.daemon=false
2+
org.gradle.java.installations.auto-detect=true
3+
org.gradle.java.installations.auto-download=true
4+
5+
# Optionally, you can hint custom JDK locations (semicolon-separated on Windows):
6+
# org.gradle.java.installations.paths=C:\\jdks\\jdk-11;C:\\jdks\\jdk-21
7+
8+
# To run Gradle itself on a specific JDK (machine-specific), prefer setting JAVA_HOME
9+
# before invoking Gradle or use --java-home on the command line.

gradle/java-compiler-settings.gradle

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,14 @@
1010
* SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause
1111
******************************************************************************/
1212

13+
// Use central version from gradle/versions.gradle
14+
1315
java {
14-
sourceCompatibility = JavaVersion.VERSION_11
16+
sourceCompatibility = JavaVersion.toVersion(versions.java)
17+
// Use same Java version for compilation and task launches
18+
toolchain {
19+
languageVersion = JavaLanguageVersion.of(versions.java as Integer)
20+
}
1521
}
1622

1723
tasks.withType(Javadoc) {
@@ -21,6 +27,15 @@ tasks.withType(Javadoc) {
2127

2228
tasks.withType(JavaCompile) {
2329
options.encoding = 'UTF-8'
30+
// Ensure cross-compilation targets specified Java version
31+
options.release = versions.java as Integer
32+
}
33+
34+
// Ensure tests run on the targeted JDK (not the Gradle JVM)
35+
tasks.withType(Test).configureEach {
36+
javaLauncher = javaToolchains.launcherFor {
37+
languageVersion = JavaLanguageVersion.of(versions.java as Integer)
38+
}
2439
}
2540

2641
task sourcesJar(type: Jar, dependsOn: classes) {

gradle/manifest-gen.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ def qualifiedVersion = baseVersion + '.v' + buildTime
2121
jar.bundle.bnd (
2222
'Bundle-Version': qualifiedVersion,
2323
'Bundle-Vendor': 'Eclipse LSP4J',
24-
'Bundle-RequiredExecutionEnvironment': 'JavaSE-11',
24+
'Bundle-RequiredExecutionEnvironment': "JavaSE-${versions.java}",
2525
"-exportcontents": "org.eclipse.lsp4j.*",
2626
"-savemanifest": "build/tmp/bnd/MANIFEST.MF",
2727
)

gradle/versions.gradle

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@
1212

1313
version = '1.0.0-SNAPSHOT'
1414

15-
ext.versions = [
15+
ext.versions = [
16+
'java': 11,
17+
1618
'xtend_lib': '2.32.0',
1719
'guava': '[32.1.2,34)',
1820
'gson': '[2.9.1,3.0)',

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)