HMCL/javafx.gradle.kts

129 lines
4.8 KiB
Plaintext
Raw Normal View History

2022-01-18 12:28:54 +08:00
buildscript {
repositories {
mavenCentral()
}
dependencies {
2024-10-20 21:33:55 +08:00
classpath("com.google.code.gson:gson:2.11.0")
2022-01-18 12:28:54 +08:00
}
}
2024-10-20 21:33:55 +08:00
val jfxVersion = "17.0.13"
val oldJfxVersion = "19.0.2.1"
2022-01-18 12:28:54 +08:00
data class Platform(
val name: String,
val classifier: String,
val groupId: String = "org.openjfx",
val version: String = jfxVersion
2022-01-18 12:28:54 +08:00
) {
fun fileUrl(
module: String, classifier: String, ext: String,
repo: String = "https://repo1.maven.org/maven2"
): java.net.URL =
2023-08-19 06:13:39 +08:00
java.net.URI(
"$repo/${groupId.replace('.', '/')}/javafx-$module/$version/javafx-$module-$version-$classifier.$ext"
2023-08-19 06:13:39 +08:00
).toURL()
2022-01-18 12:28:54 +08:00
}
val jfxModules = listOf("base", "graphics", "controls")
val jfxMirrorRepos = listOf("https://mirrors.cloud.tencent.com/nexus/repository/maven-public")
val jfxDependenciesFile = project.file("HMCL/src/main/resources/assets/openjfx-dependencies.json")
2022-01-18 12:28:54 +08:00
val jfxPlatforms = listOf(
2024-10-20 21:33:55 +08:00
Platform("windows-x86", "win-x86", version = oldJfxVersion),
2022-01-18 12:28:54 +08:00
Platform("windows-x86_64", "win"),
Platform("windows-arm64", "win", groupId = "org.glavo.hmcl.openjfx", version = "18.0.2+1-arm64"),
2022-01-18 12:28:54 +08:00
Platform("osx-x86_64", "mac"),
Platform("osx-arm64", "mac-aarch64"),
Platform("linux-x86_64", "linux"),
2024-10-20 21:33:55 +08:00
Platform("linux-arm32", "linux-arm32-monocle", version = oldJfxVersion),
Platform("linux-arm64", "linux-aarch64", version = oldJfxVersion),
Platform("linux-loongarch64", "linux", groupId = "org.glavo.hmcl.openjfx", version = "17.0.8-loongarch64"),
Platform("linux-loongarch64_ow", "linux", groupId = "org.glavo.hmcl.openjfx", version = "19-ea+10-loongson64"),
Platform("linux-riscv64", "linux", groupId = "org.glavo.hmcl.openjfx", version = "19.0.2.1-riscv64"),
Platform("freebsd-x86_64", "freebsd", groupId = "org.glavo.hmcl.openjfx", version = "14.0.2.1-freebsd"),
2022-01-18 12:28:54 +08:00
)
val jfxInClasspath =
try {
Class.forName("javafx.application.Application", false, this.javaClass.classLoader)
true
} catch (ignored: Throwable) {
false
}
if (!jfxInClasspath && JavaVersion.current() >= JavaVersion.VERSION_11) {
2023-08-19 06:13:39 +08:00
val os = System.getProperty("os.name").lowercase().let { osName ->
2022-01-18 12:28:54 +08:00
when {
2022-01-23 19:30:21 +08:00
osName.contains("win") -> "windows"
2022-01-18 12:28:54 +08:00
osName.contains("mac") -> "osx"
osName.contains("linux") || osName.contains("unix") -> "linux"
osName.contains("freebsd") -> "freebsd"
2022-01-18 12:28:54 +08:00
else -> null
}
}
2023-08-19 06:13:39 +08:00
val arch = when (System.getProperty("os.arch").lowercase()) {
2022-01-18 12:28:54 +08:00
"x86_64", "x86-64", "amd64", "ia32e", "em64t", "x64" -> "x86_64"
"x86", "x86_32", "x86-32", "i386", "i486", "i586", "i686", "i86pc", "ia32", "x32" -> "x86"
"arm64", "aarch64", "armv8", "armv9" -> "arm64"
else -> null
}
if (os != null && arch != null) {
2022-01-23 19:30:21 +08:00
val platform = jfxPlatforms.find { it.name == "$os-$arch" }
2022-01-18 12:28:54 +08:00
if (platform != null) {
val groupId = platform.groupId
val version = platform.version
2022-01-18 12:28:54 +08:00
val classifier = platform.classifier
rootProject.subprojects {
for (module in jfxModules) {
2023-02-06 22:54:41 +08:00
dependencies.add("compileOnly", "$groupId:javafx-$module:$version:$classifier")
dependencies.add("testImplementation", "$groupId:javafx-$module:$version:$classifier")
2022-01-18 12:28:54 +08:00
}
}
}
}
}
rootProject.tasks.create("generateOpenJFXDependencies") {
doLast {
val jfxDependencies = jfxPlatforms.associate { platform ->
platform.name to jfxModules.map { module ->
2022-01-18 12:28:54 +08:00
mapOf(
"module" to "javafx.$module",
"groupId" to platform.groupId,
"artifactId" to "javafx-$module",
"version" to platform.version,
2022-01-18 12:28:54 +08:00
"classifier" to platform.classifier,
"sha1" to platform.fileUrl(module, platform.classifier, "jar.sha1").readText()
)
}
}
jfxDependenciesFile.parentFile.mkdirs()
jfxDependenciesFile.writeText(
com.google.gson.GsonBuilder().setPrettyPrinting().create().toJson(jfxDependencies)
)
}
}
// Ensure that the mirror repository caches files
rootProject.tasks.create("preTouchOpenJFXDependencies") {
doLast {
for (repo in jfxMirrorRepos) {
for (platform in jfxPlatforms) {
for (module in jfxModules) {
2022-01-20 19:26:17 +08:00
val url = platform.fileUrl(module, platform.classifier, "jar", repo = repo)
logger.quiet("Getting $url")
2022-01-18 12:28:54 +08:00
try {
url.readBytes()
} catch (e: Throwable) {
logger.warn("An exception occurred while pre touching $url", e)
}
}
}
}
}
}