feat(build): centralize Java toolchain language version configuration (#6894)

# Description of Changes

This change centralizes the Java toolchain language version into a
single `buildJavaLanguageVersion` variable and reuses it across all Java
compilation tasks to ensure consistent toolchain selection.

### What was changed

- Introduced a shared `buildJavaLanguageVersion` variable derived from
the optional `javaVersion` project property, defaulting to Java 25.
- Updated the root project's Java toolchain configuration to use the
shared variable.
- Updated all subproject Java toolchain configurations to reference the
same shared variable instead of a hardcoded language version.
- Explicitly configured the `compileRestartHelper` task to use a
`javaCompiler` resolved from the same shared toolchain version.

### Why the change was made

- Eliminate duplicated Java language version definitions.
- Ensure all compilation tasks use the same Java toolchain
configuration.
- Allow the `javaVersion` project property to consistently affect the
root project, subprojects, and the restart helper compilation task.
- Simplify future Java version upgrades by requiring changes in only one
location.

---

## Checklist

### General

- [ ] I have read the [Contribution
Guidelines](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/CONTRIBUTING.md)
- [ ] I have read the [Stirling-PDF Developer
Guide](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/DeveloperGuide.md)
(if applicable)
- [ ] I have read the [How to add new languages to
Stirling-PDF](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/devGuide/HowToAddNewLanguage.md)
(if applicable)
- [ ] I have performed a self-review of my own code
- [ ] My changes generate no new warnings

### Documentation

- [ ] I have updated relevant docs on [Stirling-PDF's doc
repo](https://github.com/Stirling-Tools/Stirling-Tools.github.io/blob/main/docs/)
(if functionality has heavily changed)
- [ ] I have read the section [Add New Translation
Tags](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/devGuide/HowToAddNewLanguage.md#add-new-translation-tags)
(for new translation tags only)

### Translations (if applicable)

- [ ] I ran
[`scripts/counter_translation.py`](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/docs/counter_translation.md)

### UI Changes (if applicable)

- [ ] Screenshots or videos demonstrating the UI changes are attached
(e.g., as comments or direct attachments in the PR)

### Testing (if applicable)

- [ ] I have run `task check` to verify linters, typechecks, and tests
pass
- [ ] I have tested my changes locally. Refer to the [Testing
Guide](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/DeveloperGuide.md#7-testing)
for more details.
This commit is contained in:
Ludy
2026-07-22 07:10:19 +00:00
committed by GitHub
parent e24a30828b
commit a4ac034a18
+16 -8
View File
@@ -49,11 +49,15 @@ ext {
modernJavaVersion = 25
}
def buildJavaMajorVersion = (project.findProperty('javaVersion') ?: ext.modernJavaVersion).toString().toInteger()
def buildJavaLanguageVersion = JavaLanguageVersion.of(buildJavaMajorVersion)
def buildJavaVersion = JavaVersion.toVersion(buildJavaMajorVersion.toString())
java {
sourceCompatibility = JavaVersion.VERSION_25
targetCompatibility = JavaVersion.VERSION_25
sourceCompatibility = buildJavaVersion
targetCompatibility = buildJavaVersion
toolchain {
languageVersion = JavaLanguageVersion.of(project.findProperty('javaVersion')?.toString() ?: '25')
languageVersion = buildJavaLanguageVersion
}
}
@@ -174,10 +178,10 @@ subprojects {
apply from: rootProject.file('gradle/spotless.gradle')
java {
sourceCompatibility = JavaVersion.VERSION_25
targetCompatibility = JavaVersion.VERSION_25
sourceCompatibility = buildJavaVersion
targetCompatibility = buildJavaVersion
toolchain {
languageVersion = JavaLanguageVersion.of(25)
languageVersion = buildJavaLanguageVersion
}
}
@@ -272,7 +276,7 @@ subprojects {
tasks.withType(JavaCompile).configureEach {
options.encoding = "UTF-8"
options.release = rootProject.ext.modernJavaVersion
options.release = buildJavaMajorVersion
if (!project.hasProperty("noSpotless")) {
dependsOn "spotlessApply"
}
@@ -667,10 +671,14 @@ tasks.register('compileRestartHelper', JavaCompile) {
source = fileTree(dir: 'scripts', include: 'RestartHelper.java')
classpath = files()
destinationDirectory = layout.buildDirectory.dir("restart-helper-classes")
def restartMajorVersion = project.ext.modernJavaVersion
def restartMajorVersion = buildJavaMajorVersion
def restartLanguageVersion = JavaLanguageVersion.of(restartMajorVersion)
def restartCompatibility = JavaVersion.toVersion(restartMajorVersion.toString())
sourceCompatibility = restartCompatibility
targetCompatibility = restartCompatibility
javaCompiler = javaToolchains.compilerFor {
languageVersion = restartLanguageVersion
}
options.release.set(restartMajorVersion)
}