Skip to content

Commit 92bbe1e

Browse files
authored
Defer Adoptium API call until a JavaFX download task needs it (#7579)
`latestJavaVersion` was eagerly invoked on every Gradle invocation (`}(javaVersion)`), making each `./gradlew <anything>` round-trip to api.adoptium.net even for `help`, `tasks`, or any local-only target. Convert it to a memoized closure consumed at use sites that already sit inside lazy `tasks.register(...)` bodies (`downloadJfxMods`, `downloadJavaFXLocal`). The network call now fires at most once per build, and only when one of those JavaFX download tasks is realized. Closes OPTIMIZATION.md item #2.
1 parent bd5f4e5 commit 92bbe1e

1 file changed

Lines changed: 10 additions & 7 deletions

File tree

build.gradle

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -66,14 +66,17 @@ ext {
6666
// Java version. It will affect JavaFX version too.
6767
javaVersion = 25
6868

69-
// The Eclipse Adoptium API will return the latest patch release for the majorJava version set
69+
// The Eclipse Adoptium API returns the latest patch release for the majorJava version set.
70+
// The closure is memoized so the network call fires at most once per Gradle invocation,
71+
// and only when a JavaFX/JDK download task actually consumes the value (the use sites
72+
// sit inside lazy tasks.register bodies).
7073
latestJavaVersion = { majorJavaVersion ->
7174
def uri = new URI("https://api.adoptium.net/v3/assets/feature_releases/${majorJavaVersion}/ga?architecture=x64&page=0&page_size=1&project=jdk&sort_order=DESC&vendor=eclipse")
7275
def parsedJson = new JsonSlurper().parse(uri.toURL())
7376

74-
return parsedJson.first()
77+
parsedJson.first()
7578
.version_data.with { [major, minor, security].join('.') }
76-
}(javaVersion)
79+
}.memoize()
7780
}
7881

7982
// Configure Java, in particular the version to test/compile/run with
@@ -560,8 +563,8 @@ tasks.register("extractJdk", Copy) {
560563
tasks.register("downloadJfxMods", Download) {
561564
description = "Downloads JavaFX jmods for the host platform"
562565
dependsOn "extractJdk"
563-
def fileName = "openjfx-${latestJavaVersion}_${hostJfxOsPackage}${hostJfxArchSuffix}_bin-jmods.zip"
564-
src "https://download2.gluonhq.com/openjfx/${latestJavaVersion}/${fileName}"
566+
def fileName = "openjfx-${latestJavaVersion(javaVersion)}_${hostJfxOsPackage}${hostJfxArchSuffix}_bin-jmods.zip"
567+
src "https://download2.gluonhq.com/openjfx/${latestJavaVersion(javaVersion)}/${fileName}"
565568
dest jdksDir.file("jfx_jmods_${hostOs}_${hostArch}.zip")
566569
overwrite false
567570
useETag true
@@ -615,9 +618,9 @@ tasks.register("downloadJavaFXLocal", Download) {
615618
println("Downloading JavaFX SDK for use in local testing for ${currentOS} ${hostArchitecture}.")
616619
}
617620

618-
def fileName = "openjfx-${project.ext.latestJavaVersion}_${currentOS}${archAppend}_bin-sdk.zip"
621+
def fileName = "openjfx-${project.ext.latestJavaVersion(project.ext.javaVersion)}_${currentOS}${archAppend}_bin-sdk.zip"
619622

620-
src "https://download2.gluonhq.com/openjfx/${project.ext.latestJavaVersion}/${fileName}"
623+
src "https://download2.gluonhq.com/openjfx/${project.ext.latestJavaVersion(project.ext.javaVersion)}/${fileName}"
621624
dest layout.projectDirectory.file("mods/${fileName}")
622625
overwrite false
623626
useETag true

0 commit comments

Comments
 (0)