Skip to content

Commit 746e0d2

Browse files
committed
Use toolchains to configure build and test Java version
1 parent a8dbb49 commit 746e0d2

5 files changed

Lines changed: 85 additions & 13 deletions

File tree

.github/workflows/run-tests.yml

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,25 @@ permissions:
88

99
jobs:
1010
build:
11+
strategy:
12+
matrix:
13+
java:
14+
- version: 17
15+
javaInstall: 17
16+
buildProfile: 17
17+
testProfile: 17
18+
- version: 17-test-21
19+
javaInstall: |
20+
17
21+
21
22+
buildProfile: 17
23+
testProfile: 21
24+
- version: 17-test-25
25+
javaInstall: |
26+
17
27+
25
28+
buildProfile: 17
29+
testProfile: 25
1130
runs-on: ubuntu-latest
1231
steps:
1332
- name: Login to Docker Hub
@@ -21,22 +40,22 @@ jobs:
2140
firebird_root_password: 'masterkey'
2241
firebird_conf: 'WireCrypt=Enabled,AuthServer=Srp256;Srp;Legacy_Auth;Srp224;Srp384;Srp512,UserManager=Srp;Legacy_UserManager'
2342
- uses: actions/checkout@v6
24-
- name: Set up Java 17
43+
- name: Set up Java ${{ matrix.java.version }}
2544
uses: actions/setup-java@v5
2645
with:
27-
java-version: '17'
46+
java-version: ${{ matrix.java.javaInstall }}
2847
distribution: 'temurin'
2948
- name: Setup Gradle
3049
uses: gradle/actions/setup-gradle@0723195856401067f7a2779048b490ace7a47d7c
3150
with:
3251
cache-read-only: ${{ github.ref != 'refs/heads/master' }}
3352
- name: Build with Gradle
34-
run: ./gradlew test -Ptest.dbondocker=true -Ptest.db.dir=/var/lib/firebird/data
53+
run: ./gradlew test -PbuildProfile=${{ matrix.java.buildProfile }} -PtestProfile=${{ matrix.java.testProfile }} -Ptest.dbondocker=true -Ptest.db.dir=/var/lib/firebird/data
3554
- name: Store Report Artifact
3655
uses: actions/upload-artifact@v7
3756
if: always()
3857
with:
39-
name: report-artifacts
58+
name: report-artifacts-${{ matrix.java.version }}
4059
path: build/reports
4160
compression-level: 9
4261
retention-days: 7

build-properties.gradle

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,24 @@ def buildTime = LocalDateTime.now()
2424
ext.'build.id' = buildTime.format('yyyyMMddHHmm')
2525
ext.YEAR = buildTime.format('yyyy')
2626

27-
// Build profile
28-
ext.'maven.jdkversion' = 'java17'
27+
// Build profile (target Java version)
28+
def buildProfileProp = findProperty('buildProfile') as String
29+
def buildMatcher = buildProfileProp =~ /^(?:java)?(\d+)$/
30+
ext.buildProfile = buildMatcher ? buildMatcher.group(1) as Integer : 17
31+
println "Build profile: Java ${ext.buildProfile}"
32+
if (ext.buildProfile != 17) {
33+
println "WARNING: Java target version ${ext.buildProfile} (buildProfile) is not a baseline version and will not be published to Maven."
34+
}
35+
36+
// As we only publish the Java 17 version, we don't do further mapping for higher JDBC versions
2937
ext.'specification.version' = '4.3'
3038

39+
// Test profile (test Java version)
40+
def testProfileProp = findProperty('testProfile') as String
41+
def testMatcher = testProfileProp =~ /^(?:java)?(\d+)$/
42+
ext.testProfile = testMatcher ? testMatcher.group(1) as Integer : ext.buildProfile
43+
println "Test profile: Java ${ext.testProfile}"
44+
3145
ext.'version.simple' = "${project.'version.major'}.${project.'version.minor'}.${project.'version.revision'}".toString()
3246
ext.'version.maven' = "${project.'version.simple'}${project.'version.tag'}".toString()
3347

build.gradle

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,21 @@ import org.asciidoctor.gradle.jvm.AsciidoctorTask
66
/*
77
Gradle build script for Jaybird - Firebird JDBC driver.
88
9+
Define target Java version:
10+
- -PbuildProfile=17 : Java 17 (supported)
11+
or not specified
12+
- -PbuildProfile=NN : Java NN (not publishable)
13+
with NN > 17
14+
15+
Build profiles other than 17 will not be published to Maven.
16+
17+
Define (other) Java version to test:
18+
- -PtestProfile=NN with NN >= 17
19+
20+
If not specified, the test profile is the same as buildProfile.
21+
22+
For historic reasons, both buildProfile and testProfile also accept javaNN.
23+
924
Uploading archives:
1025
1126
publish -PcredentialsPassphrase=<credentials password>
@@ -29,9 +44,22 @@ version = project.'version.maven'
2944
allprojects {
3045
tasks.withType(JavaCompile).configureEach {
3146
options.encoding = 'UTF-8'
47+
int buildProfile = project.buildProfile
48+
options.release = buildProfile
49+
javaCompiler = javaToolchains.compilerFor {
50+
languageVersion = JavaLanguageVersion.of((int) buildProfile)
51+
}
3252
}
3353
tasks.withType(Test).configureEach {
3454
systemProperty 'file.encoding', 'UTF-8'
55+
javaLauncher = javaToolchains.launcherFor {
56+
languageVersion = JavaLanguageVersion.of((int) project.testProfile)
57+
}
58+
}
59+
tasks.withType(Javadoc).configureEach {
60+
javadocTool = javaToolchains.javadocToolFor {
61+
languageVersion = JavaLanguageVersion.of((int) project.testProfile)
62+
}
3563
}
3664
}
3765

@@ -40,8 +68,9 @@ base {
4068
}
4169

4270
java {
43-
sourceCompatibility = JavaVersion.VERSION_17
44-
targetCompatibility = JavaVersion.VERSION_17
71+
def javaVersion = JavaLanguageVersion.of((int) project.buildProfile)
72+
sourceCompatibility = javaVersion
73+
targetCompatibility = javaVersion
4574
withJavadocJar()
4675
withSourcesJar()
4776
}
@@ -161,13 +190,12 @@ tasks.named('assemble') {
161190
jar {
162191
manifest {
163192
attributes(
164-
'Created-By': "${System.getProperty('java.vm.version')} (${System.getProperty('java.vm.vendor')})",
165193
'Specification-Title': project.'specification.title',
166194
'Specification-Version': project.'specification.version',
167195
'Specification-Vendor': project.'specification.vendor',
168196
'Implementation-Title': project.'implementation.title',
169197
'Implementation-Url': project.'implementation.url',
170-
'Implementation-Version': "$project.version (build: variant=$project.mavenName tag=${project.'version.svntag'} date=${project.'build.id'})",
198+
'Implementation-Version': "$project.version (build: variant=$project.mavenName tag=${project.'version.svntag'} date=${project.'build.id'} profile=${project.buildProfile})",
171199
'Implementation-Vendor': project.'implementation.vendor',
172200
'Implementation-Vendor-Id': project.'implementation.vendor.id',
173201
'Bundle-License': 'LGPL-2.1-or-later OR LGPL-2.1-or-later AND BSD-3-Clause',

devdoc/build-documentation.md

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,23 @@ please contribute using a pull request, or ask on [firebird-java](https://groups
1010
## Running the build
1111

1212
The build uses Gradle wrapper, which is included in the repository. The current
13-
minimum version is Java 17.
13+
minimum version is Java 17. The build target (buildProfile) defaults to Java 17,
14+
independent of the Java version running Gradle.
15+
16+
The target Java version is determined by passing `-PbuildProfile=NN`, where `NN`
17+
is the desired Java version. The default is `17`. Versions other than `17` are
18+
not published to Maven.
19+
20+
By default, tests are run with that `buildProfile` version. This can be
21+
overridden with `-PtestProfile=NN`. For historic reasons, `javaNN` is also
22+
accepted by both properties.
1423

1524
To run with a specific Java version, we suggest creating a Java-specific launch
1625
script. For example, for Windows create a batch file with:
1726

1827
```
1928
@echo off
20-
set JAVA_HOME=C:\Program Files\Java\jdk-19
21-
call gradlew.bat %*
29+
call gradlew.bat -PbuildProfile=21 %*
2230
```
2331

2432
### Default build

publish.gradle

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,9 @@ publishing {
186186

187187
allprojects {
188188
tasks.withType(PublishToMavenRepository).each {
189+
it.onlyIf('Only publish Java 17 builds') {
190+
project.buildProfile == 17
191+
}
189192
it.doFirst {
190193
if (findProperty('centralUsername') == null || findProperty('centralPassword') == null) {
191194
throw new RuntimeException('No credentials for publishing, make sure to specify the properties ' +

0 commit comments

Comments
 (0)