Skip to content

Commit c872ff1

Browse files
sebthomjonahgraham
andcommitted
build: use JDK 17 or 21 to run Gradle; compile/test with JDK 11, 17, and 21
- on CI build with Java 21, test with 11, 17 and 21 - on Dev machine, build can also be 17 - Decouple JDK to run Gradle from the JDK used to compile/test. - Use Java toolchains to select JDK 11 for compilation and test - Set javac --release 11 for consistent API/bytecode. - Launch Test tasks with the JDK 11 toolchain for non-xtend cases - Launch test tasks with JDK 17, 21 for all tests - Update Tycho to newer version that works with Java 21 Co-authored-by: Jonah Graham <[email protected]>
1 parent 1082fa0 commit c872ff1

File tree

8 files changed

+112
-18
lines changed

8 files changed

+112
-18
lines changed

.github/workflows/validate.yml

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,15 @@ jobs:
4545
uses: actions/checkout@v5 # https://github.com/actions/checkout
4646

4747

48-
- name: "Install: JDK 11 ☕"
48+
- name: "Install: JDKs for building and testing"
4949
uses: actions/setup-java@v5 # https://github.com/actions/setup-java
5050
with:
5151
distribution: temurin
52-
java-version: 11
52+
java-version: |
53+
11
54+
17
55+
21
5356
cache: gradle
5457

55-
5658
- name: Build with Gradle 🏗️
57-
run: ./gradlew build
59+
run: ./gradlew build testOlderJavas

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: 83 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,32 @@
1010
* SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause
1111
******************************************************************************/
1212

13+
// Use central version from gradle/versions.gradle
14+
15+
// --- Enforce Java version for running Gradle itself ---
16+
def currentJava = JavaVersion.current()
17+
def minJava = JavaVersion.VERSION_17 // xtend requires Java >= 17
18+
def maxJava = JavaVersion.VERSION_21 // Gradle 9.x is required for Java 25
19+
20+
if (currentJava < minJava || currentJava > maxJava) {
21+
throw new GradleException("""
22+
This build must be run with Java between ${minJava} and ${maxJava}.
23+
24+
Current Java:
25+
JavaVersion.current() = ${currentJava}
26+
java.version = ${System.getProperty('java.version')}
27+
java.home = ${System.getProperty('java.home')}
28+
29+
Please switch your JAVA_HOME or use the Gradle wrapper with a compatible JDK.
30+
31+
In addition, to run testOlderJavas tasks Java 17 and Java 11 must be discovrable.
32+
See https://docs.gradle.org/8.6/userguide/toolchains.html#sec:auto_detection
33+
""")
34+
}
35+
1336
java {
14-
sourceCompatibility = JavaVersion.VERSION_11
37+
sourceCompatibility = JavaVersion.toVersion(versions.java)
38+
targetCompatibility = JavaVersion.toVersion(versions.java)
1539
}
1640

1741
tasks.withType(Javadoc) {
@@ -21,6 +45,8 @@ tasks.withType(Javadoc) {
2145

2246
tasks.withType(JavaCompile) {
2347
options.encoding = 'UTF-8'
48+
// Ensure cross-compilation targets specified Java version
49+
options.release = versions.java as Integer
2450
}
2551

2652
task sourcesJar(type: Jar, dependsOn: classes) {
@@ -87,3 +113,59 @@ if (findProperty('ignoreTestFailures') == 'true') {
87113
ignoreFailures = true
88114
}
89115
}
116+
117+
def testDir = file('src/test/java')
118+
def xtendTestClassPatterns = []
119+
120+
if (testDir.exists()) {
121+
testDir.eachFileRecurse { File f ->
122+
if (f.name.endsWith('.xtend')) {
123+
// Path relative to src/test/java, with Unix-ish separators
124+
def rel = testDir.toPath().relativize(f.toPath()).toString()
125+
rel = rel.replace(File.separatorChar, '/' as char)
126+
127+
// Replace .xtend with .class, wildcard anything before it
128+
// e.g. com/foo/BarTest.xtend -> **/com/foo/BarTest.class
129+
def classPattern = "**/${rel[0..-6]}class"
130+
xtendTestClassPatterns << classPattern
131+
}
132+
}
133+
}
134+
135+
tasks.register('testJava11', Test) {
136+
description = 'Runs non-xtend tests on Java 11 JVM'
137+
group = 'verification'
138+
139+
testClassesDirs = sourceSets.test.output.classesDirs
140+
classpath = sourceSets.test.runtimeClasspath
141+
142+
// Current version of xtend require JVM >= 17 to run,
143+
// so exclude xtend based tests
144+
if (!xtendTestClassPatterns.isEmpty()) {
145+
exclude xtendTestClassPatterns
146+
}
147+
148+
javaLauncher.set(
149+
javaToolchains.launcherFor {
150+
languageVersion = JavaLanguageVersion.of(11)
151+
}
152+
)
153+
}
154+
155+
tasks.register('testJava17', Test) {
156+
description = 'Runs tests on Java 17 JVM'
157+
group = 'verification'
158+
159+
testClassesDirs = sourceSets.test.output.classesDirs
160+
classpath = sourceSets.test.runtimeClasspath
161+
162+
javaLauncher.set(
163+
javaToolchains.launcherFor {
164+
languageVersion = JavaLanguageVersion.of(17)
165+
}
166+
)
167+
}
168+
169+
tasks.register('testOlderJavas') {
170+
dependsOn tasks.named('testJava17'), tasks.named('testJava11')
171+
}

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 & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ version = '1.0.0-SNAPSHOT'
1414

1515
ext.versions = [
1616
'xtend_lib': '2.32.0',
17+
// Additional JDK version configuration is in java-compiler-settings
18+
'java': '11',
19+
1720
'guava': '[32.1.2,34)',
1821
'gson': '[2.9.1,3.0)',
1922

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")

releng/build.Jenkinsfile

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ pipeline {
77
}
88
tools {
99
maven 'apache-maven-latest'
10-
jdk 'temurin-jdk11-latest'
10+
// Default JDK picked up from here, build and test requires
11+
// older JDKs too, which are discovered by gradle from ~/.m2/toolchains.xml
12+
jdk 'temurin-jdk21-latest'
1113
}
1214
options {
1315
timestamps()
@@ -32,12 +34,13 @@ pipeline {
3234
sh "echo $JAVA_HOME"
3335
sh "java -version"
3436
sh "which java"
37+
sh "cat ~/.m2/toolchains.xml"
3538
sh "./gradlew \
3639
--no-daemon \
3740
-PignoreTestFailures=true \
3841
--refresh-dependencies \
3942
--continue \
40-
clean build signJar publish \
43+
clean build testOlderJavas signJar publish \
4144
"
4245
}
4346
}
@@ -81,8 +84,8 @@ pipeline {
8184
}
8285
post {
8386
always {
84-
junit '**/build/test-results/test/*.xml'
85-
archiveArtifacts 'build/**'
87+
junit '**/build/test-results/**/*.xml'
88+
archiveArtifacts 'build/**,**/build/reports/'
8689
}
8790
cleanup {
8891
script {

releng/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
<packaging>pom</packaging>
99

1010
<properties>
11-
<tycho-version>2.7.5</tycho-version>
11+
<tycho-version>5.0.0</tycho-version>
1212
<root-dir>${maven.multiModuleProjectDirectory}/..</root-dir>
1313
</properties>
1414

0 commit comments

Comments
 (0)