Inceptum/launcher-dist/build.gradle.kts

136 lines
4.6 KiB
Plaintext

import io.gitlab.jfronny.scripts.*
import java.nio.file.Files
import java.nio.file.Path
plugins {
inceptum.`application-standalone`
org.beryx.jlink
}
application {
mainClass.set("io.gitlab.jfronny.inceptum.Inceptum")
mainModule.set("io.gitlab.jfronny.inceptum.launcher.dist")
applicationName = "Inceptum"
}
dependencies {
implementation(projects.launcher)
implementation(projects.launcherCli)
implementation(projects.launcherImgui)
}
tasks.shadowJar {
archiveClassifier.set(rootProject.extra["flavorProp"] as String)
archiveBaseName.set("Inceptum")
exclude("about.html")
exclude("plugin.properties")
exclude("META-INF/**")
}
(components["java"] as AdhocComponentWithVariants).withVariantsFromConfiguration(configurations["shadowRuntimeElements"]) {
skip()
}
publishing {
publications {
create<MavenPublication>("mavenJava") {
from(components["java"])
}
}
}
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
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"
))
}
}
}
}
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)
}
}
}
}
}