Inceptum/launcher-dist/build.gradle.kts

136 lines
4.6 KiB
Plaintext
Raw Normal View History

2023-05-05 23:06:58 +02:00
import io.gitlab.jfronny.scripts.*
import java.nio.file.Files
import java.nio.file.Path
2023-05-05 23:06:58 +02:00
2022-09-06 11:15:21 +02:00
plugins {
inceptum.`application-standalone`
org.beryx.jlink
2022-09-06 11:15:21 +02:00
}
application {
mainClass.set("io.gitlab.jfronny.inceptum.Inceptum")
2023-05-05 23:06:58 +02:00
mainModule.set("io.gitlab.jfronny.inceptum.launcher.dist")
applicationName = "Inceptum"
2022-09-06 11:15:21 +02:00
}
dependencies {
implementation(projects.launcher)
implementation(projects.launcherCli)
implementation(projects.launcherImgui)
2022-09-06 11:15:21 +02:00
}
tasks.shadowJar {
archiveClassifier.set(rootProject.extra["flavorProp"] as String)
archiveBaseName.set("Inceptum")
exclude("about.html")
exclude("plugin.properties")
exclude("META-INF/**")
}
2022-09-06 13:28:28 +02:00
(components["java"] as AdhocComponentWithVariants).withVariantsFromConfiguration(configurations["shadowRuntimeElements"]) {
2022-09-06 12:35:29 +02:00
skip()
}
2022-09-06 11:15:21 +02:00
publishing {
publications {
2022-11-03 15:39:44 +01:00
create<MavenPublication>("mavenJava") {
from(components["java"])
2022-09-06 11:15:21 +02:00
}
}
}
val flavor: String by rootProject.extra
val os = org.gradle.internal.os.OperatingSystem.current()!!
val crosscompile = flavor == "windows" && os.isLinux && project.hasProperty("crosscompile")
val verifyFlavorConfiguration by tasks.registering {
when (flavor) {
"macos" -> if (!os.isMacOsX) throw IllegalArgumentException("Cross-compilation to MacOS is unsupported!")
"windows" -> if (!os.isWindows && !crosscompile) {
if (os.isLinux) throw IllegalArgumentException("Cross-compilation to Windows is not enabled, please do so to build this")
else throw IllegalArgumentException("Cross-compilation to Windows from this platform is unsupported!")
}
"linux" -> if (!os.isLinux) throw IllegalArgumentException("Cross-compilation to Linux is unsupported!")
else -> throw IllegalArgumentException("Unexpected flavor: $flavor")
}
}
tasks.prepareMergedJarsDir { dependsOn(verifyFlavorConfiguration) }
tasks.createMergedModule { dependsOn(verifyFlavorConfiguration) }
tasks.createDelegatingModules { dependsOn(verifyFlavorConfiguration) }
tasks.prepareModulesDir { dependsOn(verifyFlavorConfiguration) }
tasks.jlink { dependsOn(verifyFlavorConfiguration) }
tasks.jlinkZip { dependsOn(verifyFlavorConfiguration) }
tasks.suggestMergedModuleInfo { dependsOn(verifyFlavorConfiguration) }
tasks.jpackageImage { dependsOn(verifyFlavorConfiguration) }
tasks.jpackage { dependsOn(verifyFlavorConfiguration) }
if (crosscompile) System.setProperty("badass.jlink.jpackage.home", "/root/jpackage-win")
jlink {
if (crosscompile) javaHome.set("/root/jpackage-win")
addOptions(
"--strip-debug",
"--compress", "2",
"--no-header-files",
"--no-man-pages",
"--verbose"
)
launcher {
name = application.applicationName
}
if (crosscompile) targetPlatform("win", "/root/java")
jpackage {
imageName = application.applicationName
2023-05-05 23:06:58 +02:00
if (crosscompile) {
outputDir = "/root/jpackage-out"
imageOutputDir = File(outputDir)
installerOutputDir = File(outputDir)
}
appVersion = versionStripped
// vendor
when (flavor) {
"macos" -> {
installerType = "app-image"
installerOptions.addAll(listOf(
"--mac-package-name", "inceptum"
))
}
"windows" -> {
installerType = "msi"
installerOptions.addAll(listOf(
"--win-per-user-install",
"--win-dir-chooser",
"--win-menu",
"--win-upgrade-uuid", "180becd8-a867-40d4-86ef-20949cae68b5" // Update this UUID if you fork the project!!!
))
//imageOptions.add("--win-console") // Enable this for debugging
}
else -> {
// might also be able to push rpm with appropriate image
installerType = "deb"
installerOptions.addAll(listOf(
"--linux-package-name", "inceptum",
"--linux-shortcut"
))
}
}
}
2023-05-05 23:06:58 +02:00
}
if (crosscompile) {
tasks.jpackage {
doLast {
val src = Path.of("/root/jpackage-out")
val trg = layout.buildDirectory.dir("jpackage").get().asFile.toPath()
Files.createDirectories(trg)
Files.list(src).use {
it.filter { Files.isRegularFile(it) }.forEach {
val t = trg.resolve(it.fileName.toString())
println("Moving $it to $t")
Files.move(it, t)
}
2023-05-05 23:06:58 +02:00
}
}
}
}