Skip to content

Commit 739a68c

Browse files
committed
Use toolchains to configure build and test Java version
1 parent c26f8ed commit 739a68c

7 files changed

Lines changed: 86 additions & 15 deletions

File tree

.github/workflows/run-tests.yml

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

77
jobs:
88
build:
9+
strategy:
10+
matrix:
11+
java:
12+
- version: 17
13+
javaInstall: 17
14+
buildProfile: 17
15+
testProfile: 17
16+
- version: 17-test-21
17+
javaInstall: |
18+
17
19+
21
20+
buildProfile: 17
21+
testProfile: 21
22+
- version: 17-test-25
23+
javaInstall: |
24+
17
25+
25
26+
buildProfile: 17
27+
testProfile: 25
928
runs-on: ubuntu-latest
1029
steps:
1130
- name: Login to Docker Hub
@@ -19,22 +38,22 @@ jobs:
1938
firebird_root_password: 'masterkey'
2039
firebird_conf: 'WireCrypt=Enabled,AuthServer=Srp256;Srp;Legacy_Auth;Srp224;Srp384;Srp512,UserManager=Srp;Legacy_UserManager'
2140
- uses: actions/checkout@v6
22-
- name: Set up Java 17
41+
- name: Set up Java ${{ matrix.java.version }}
2342
uses: actions/setup-java@v5
2443
with:
25-
java-version: '17'
44+
java-version: ${{ matrix.java.javaInstall }}
2645
distribution: 'temurin'
2746
- name: Setup Gradle
2847
uses: gradle/actions/setup-gradle@0723195856401067f7a2779048b490ace7a47d7c
2948
with:
3049
cache-read-only: ${{ github.ref != 'refs/heads/Branch_6_0' }}
3150
- name: Build with Gradle
32-
run: ./gradlew test -Ptest.dbondocker=true -Ptest.db.dir=/var/lib/firebird/data
51+
run: ./gradlew test -PbuildProfile=${{ matrix.java.buildProfile }} -PtestProfile=${{ matrix.java.testProfile }} -Ptest.dbondocker=true -Ptest.db.dir=/var/lib/firebird/data
3352
- name: Store Report Artifact
3453
uses: actions/upload-artifact@v7
3554
if: always()
3655
with:
37-
name: report-artifacts
56+
name: report-artifacts-${{ matrix.java.version }}
3857
path: build/reports
3958
compression-level: 9
4059
retention-days: 7

build-properties.gradle

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,24 @@ def buildTime = new Date()
2020
ext.'build.id' = buildTime.format('yyyyMMddHHmm')
2121
ext.YEAR = buildTime.format("yyyy")
2222

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

35+
// Test profile (test Java version)
36+
def testProfileProp = findProperty('testProfile') as String
37+
def testMatcher = testProfileProp =~ /^(?:java)?(\d+)$/
38+
ext.testJava = testMatcher ? testMatcher.group(1) as Integer : ext.buildJava
39+
println "Test profile: Java ${ext.testJava}"
40+
2741
ext.'version.simple' = "${project.'version.major'}.${project.'version.minor'}.${project.'version.revision'}".toString()
2842
ext.'version.maven' = "${project.'version.simple'}${project.'version.tag'}".toString()
2943

build.gradle

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,21 @@ import org.asciidoctor.gradle.jvm.AsciidoctorTask
44
/*
55
Gradle build script for Jaybird - Firebird JDBC driver.
66
7+
Define target Java version:
8+
- -PbuildProfile=17 : Java 17 (supported)
9+
or not specified
10+
- -PbuildProfile=NN : Java NN (not publishable)
11+
with NN > 17
12+
13+
Build profiles other than 17 will not be published to Maven.
14+
15+
Define (other) Java version to test:
16+
- -PtestProfile=NN with NN >= 17
17+
18+
If not specified, the test profile is the same as buildProfile.
19+
20+
For historic reasons, both buildProfile and testProfile also accept javaNN.
21+
722
Uploading archives:
823
924
publish -PcredentialsPassphrase=<credentials password>
@@ -27,9 +42,21 @@ version = project.'version.maven'
2742
allprojects {
2843
tasks.withType(JavaCompile).configureEach {
2944
options.encoding = 'UTF-8'
45+
options.release = project.buildJava
46+
javaCompiler = javaToolchains.compilerFor {
47+
languageVersion = JavaLanguageVersion.of((int) project.buildJava)
48+
}
3049
}
3150
tasks.withType(Test).configureEach {
3251
systemProperty 'file.encoding', 'UTF-8'
52+
javaLauncher = javaToolchains.launcherFor {
53+
languageVersion = JavaLanguageVersion.of((int) project.testJava)
54+
}
55+
}
56+
tasks.withType(Javadoc).configureEach {
57+
javadocTool = javaToolchains.javadocToolFor {
58+
languageVersion = JavaLanguageVersion.of((int) project.buildJava)
59+
}
3360
}
3461
}
3562

@@ -38,8 +65,9 @@ base {
3865
}
3966

4067
java {
41-
sourceCompatibility = JavaVersion.VERSION_17
42-
targetCompatibility = JavaVersion.VERSION_17
68+
def javaVersion = JavaLanguageVersion.of((int) project.buildJava)
69+
sourceCompatibility = javaVersion
70+
targetCompatibility = javaVersion
4371
withJavadocJar()
4472
withSourcesJar()
4573
}
@@ -158,13 +186,12 @@ tasks.named('assemble') {
158186
jar {
159187
manifest {
160188
attributes(
161-
'Created-By': "${System.getProperty('java.vm.version')} (${System.getProperty('java.vm.vendor')})",
162189
'Specification-Title': project.'specification.title',
163190
'Specification-Version': project.'specification.version',
164191
'Specification-Vendor': project.'specification.vendor',
165192
'Implementation-Title': project.'implementation.title',
166193
'Implementation-Url': project.'implementation.url',
167-
'Implementation-Version': "$project.version (build: variant=$project.mavenName tag=${project.'version.svntag'} date=${project.'build.id'})",
194+
'Implementation-Version': "$project.version (build: variant=$project.mavenName tag=${project.'version.svntag'} date=${project.'build.id'} java=${project.buildJava})",
168195
'Implementation-Vendor': project.'implementation.vendor',
169196
'Implementation-Vendor-Id': project.'implementation.vendor.id'
170197
)

chacha64-plugin/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ jar {
3636
'Created-By': "${System.getProperty('java.vm.version')} (${System.getProperty('java.vm.vendor')})",
3737
'Implementation-Title': 'Jaybird ChaCha64 wire encryption',
3838
'Implementation-Url': project.'implementation.url',
39-
'Implementation-Version': "$project.version (build: variant=$project.mavenName tag=${project.'version.svntag'} date=${project.'build.id'})",
39+
'Implementation-Version': "$project.version (build: variant=$project.mavenName tag=${project.'version.svntag'} date=${project.'build.id'} java=${project.buildJava})",
4040
'Implementation-Vendor': project.'implementation.vendor',
4141
'Implementation-Vendor-Id': project.'implementation.vendor.id'
4242
)

devdoc/build-documentation.md

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

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

1120
To run with a specific Java version, we suggest creating a Java-specific launch
1221
script. For example, for Windows create a batch file with:
1322

1423
```
1524
@echo off
16-
set JAVA_HOME=C:\Program Files\Java\jdk-19
17-
call gradlew.bat %*
25+
call gradlew.bat -PbuildProfile=21 %*
1826
```
1927

2028
### Default build

jaybird-native/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ jar {
3838
'Created-By': "${System.getProperty('java.vm.version')} (${System.getProperty('java.vm.vendor')})",
3939
'Implementation-Title': 'Jaybird Native GDS Factory Plugin',
4040
'Implementation-Url': project.'implementation.url',
41-
'Implementation-Version': "$project.version (build: variant=$project.mavenName tag=${project.'version.svntag'} date=${project.'build.id'})",
41+
'Implementation-Version': "$project.version (build: variant=$project.mavenName tag=${project.'version.svntag'} date=${project.'build.id'} java=${project.buildJava})",
4242
'Implementation-Vendor': project.'implementation.vendor',
4343
'Implementation-Vendor-Id': project.'implementation.vendor.id'
4444
)

publish.gradle

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

174174
allprojects {
175175
tasks.withType(PublishToMavenRepository).each {
176+
it.onlyIf('Only publish Java 17 builds') {
177+
project.buildJava == 17
178+
}
176179
it.doFirst {
177180
if (findProperty('centralUsername') == null || findProperty('centralPassword') == null) {
178181
throw new RuntimeException('No credentials for publishing, make sure to specify the properties ' +

0 commit comments

Comments
 (0)