Skip to content

Commit

Permalink
Download & extract JDKs as separate task
Browse files Browse the repository at this point in the history
  • Loading branch information
logandhillon committed Sep 24, 2024
1 parent e32be64 commit 44141d4
Showing 1 changed file with 52 additions and 4 deletions.
56 changes: 52 additions & 4 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,54 @@ gradle.projectsLoaded {
if (!serverDir.exists()) serverDir.mkdirs()
}

def jdkDir = file("${buildDir}/jdks")
def jdkVersion = "21"

def downloadJdk(String jdkUrl, File destinationDir) {
destinationDir.mkdirs()
def jdkArchive = new File(destinationDir, jdkUrl.substring(jdkUrl.lastIndexOf('/') + 1))

if (!jdkArchive.exists()) {
println "Downloading JDK from: $jdkUrl"
new URL(jdkUrl).withInputStream { downloadStream ->
jdkArchive.withOutputStream { outputStream ->
outputStream << downloadStream
}
}
println "Downloaded: ${jdkArchive.name}"
}

def tempDir = new File(destinationDir, "temp")
if (jdkArchive.name.endsWith('.zip')) {
copy {
from zipTree(jdkArchive)
into tempDir
}
} else if (jdkArchive.name.endsWith('.tar.gz')) {
copy {
from tarTree(resources.gzip(jdkArchive))
into tempDir
}
}

def extractedDir = tempDir.listFiles()?.find { it.isDirectory() }
if (extractedDir) {
def finalDir = new File(destinationDir, "bin")
extractedDir.renameTo(finalDir)
}

delete(tempDir)
}

task downloadJdks {
doLast {
downloadJdk("https://corretto.aws/downloads/latest/amazon-corretto-${jdkVersion}-x64-linux-jdk.tar.gz", file("${jdkDir}/linux"))
downloadJdk("https://corretto.aws/downloads/latest/amazon-corretto-${jdkVersion}-x64-windows-jdk.zip", file("${jdkDir}/win"))
downloadJdk("https://corretto.aws/downloads/latest/amazon-corretto-${jdkVersion}-aarch64-macos-jdk.tar.gz", file("${jdkDir}/mac-aarch64"))
downloadJdk("https://corretto.aws/downloads/latest/amazon-corretto-${jdkVersion}-x64-macos-jdk.tar.gz", file("${jdkDir}/mac-x64"))
}
}

jlink {
imageZip = project.file("${buildDir}/distributions/${name}-${version}.zip")
options = ['--strip-debug', '--compress', '2', '--no-header-files', '--no-man-pages', '--ignore-signing-information']
Expand All @@ -67,19 +115,19 @@ jlink {
}

targetPlatform("linux") {
jdkHome = jdkDownload("https://corretto.aws/downloads/latest/amazon-corretto-21-x64-linux-jdk.tar.gz")
jdkHome = file("${jdkDir}/linux/bin")
}

targetPlatform("win") {
jdkHome = jdkDownload("https://corretto.aws/downloads/latest/amazon-corretto-21-x64-windows-jdk.zip")
jdkHome = file("${jdkDir}/win/bin")
}

targetPlatform("mac-aarch64") {
jdkHome = jdkDownload("https://corretto.aws/downloads/latest/amazon-corretto-21-aarch64-macos-jdk.tar.gz")
jdkHome = file("${jdkDir}/mac-aarch64/bin/Contents/Home")
}

targetPlatform("mac-x64") {
jdkHome = jdkDownload("https://corretto.aws/downloads/latest/amazon-corretto-21-x64-macos-jdk.tar.gz")
jdkHome = file("${jdkDir}/mac-x64/bin/Contents/Home")
}
}

Expand Down

0 comments on commit 44141d4

Please sign in to comment.