2024-01-31 01:17:51 +07:00
|
|
|
|
2020-05-19 04:14:01 +07:00
|
|
|
import com.unciv.build.BuildConfig
|
2024-10-31 12:07:30 +07:00
|
|
|
import com.unciv.build.BuildConfig.gdxVersion
|
2020-05-19 04:14:01 +07:00
|
|
|
|
|
|
|
plugins {
|
|
|
|
id("kotlin")
|
|
|
|
}
|
|
|
|
|
|
|
|
sourceSets {
|
|
|
|
main {
|
|
|
|
java.srcDir("src/")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-01-28 17:35:29 +07:00
|
|
|
kotlin {
|
2024-02-11 00:44:47 +07:00
|
|
|
target {
|
|
|
|
compilations.all {
|
2024-02-12 05:49:08 +07:00
|
|
|
kotlinOptions.jvmTarget = JavaVersion.VERSION_1_8.toString()
|
2024-02-11 00:44:47 +07:00
|
|
|
}
|
|
|
|
}
|
2024-01-28 17:35:29 +07:00
|
|
|
}
|
|
|
|
java {
|
2024-02-12 05:49:08 +07:00
|
|
|
targetCompatibility = JavaVersion.VERSION_1_8
|
2024-01-28 17:35:29 +07:00
|
|
|
}
|
|
|
|
|
2024-10-31 12:07:30 +07:00
|
|
|
dependencies {
|
|
|
|
// See https://libgdx.com/news/2021/07/devlog-7-lwjgl3#do-i-need-to-do-anything-else
|
|
|
|
api("com.badlogicgames.gdx:gdx-lwjgl3-glfw-awt-macos:$gdxVersion")
|
|
|
|
}
|
|
|
|
|
2020-05-19 04:14:01 +07:00
|
|
|
val mainClassName = "com.unciv.app.desktop.DesktopLauncher"
|
|
|
|
val assetsDir = file("../android/assets")
|
|
|
|
val discordDir = file("discord_rpc")
|
|
|
|
val deployFolder = file("../deploy")
|
|
|
|
|
|
|
|
tasks.register<JavaExec>("run") {
|
|
|
|
dependsOn(tasks.getByName("classes"))
|
2022-05-19 07:12:18 +07:00
|
|
|
mainClass.set(mainClassName)
|
2020-05-19 04:14:01 +07:00
|
|
|
classpath = sourceSets.main.get().runtimeClasspath
|
|
|
|
standardInput = System.`in`
|
|
|
|
workingDir = assetsDir
|
|
|
|
isIgnoreExitValue = true
|
|
|
|
}
|
|
|
|
|
|
|
|
tasks.register<JavaExec>("debug") {
|
|
|
|
dependsOn(tasks.getByName("classes"))
|
2022-05-19 07:12:18 +07:00
|
|
|
mainClass.set(mainClassName)
|
2020-05-19 04:14:01 +07:00
|
|
|
classpath = sourceSets.main.get().runtimeClasspath
|
|
|
|
standardInput = System.`in`
|
|
|
|
workingDir = assetsDir
|
|
|
|
isIgnoreExitValue = true
|
|
|
|
debug = true
|
|
|
|
}
|
|
|
|
|
|
|
|
tasks.register<Jar>("dist") { // Compiles the jar file
|
|
|
|
dependsOn(tasks.getByName("classes"))
|
|
|
|
|
2020-07-24 13:30:00 +07:00
|
|
|
// META-INF/INDEX.LIST and META-INF/io.netty.versions.properties are duplicated, but I don't know why
|
|
|
|
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
|
|
|
|
|
2020-05-19 04:14:01 +07:00
|
|
|
from(files(sourceSets.main.get().output.resourcesDir))
|
|
|
|
from(files(sourceSets.main.get().output.classesDirs))
|
|
|
|
// see Laurent1967's comment on https://github.com/libgdx/libgdx/issues/5491
|
2022-05-17 22:37:12 +07:00
|
|
|
from({
|
|
|
|
(
|
|
|
|
configurations.runtimeClasspath.get().resolve() // kotlin coroutine classes live here, thanks https://stackoverflow.com/a/59021222
|
|
|
|
+ configurations.compileClasspath.get().resolve()
|
|
|
|
).map { if (it.isDirectory) it else zipTree(it) }})
|
2020-05-19 04:14:01 +07:00
|
|
|
from(files(assetsDir))
|
2023-05-04 18:21:00 +07:00
|
|
|
exclude("mods", "SaveFiles", "MultiplayerFiles", "GameSettings.json", "lasterror.txt")
|
2020-05-19 04:14:01 +07:00
|
|
|
// This is for the .dll and .so files to make the Discord RPC work on all desktops
|
|
|
|
from(files(discordDir))
|
2020-07-24 13:30:00 +07:00
|
|
|
archiveFileName.set("${BuildConfig.appName}.jar")
|
2020-11-23 02:47:46 +07:00
|
|
|
|
2020-05-19 04:14:01 +07:00
|
|
|
manifest {
|
|
|
|
attributes(mapOf("Main-Class" to mainClassName, "Specification-Version" to BuildConfig.appVersion))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-10-13 03:39:57 +07:00
|
|
|
|
|
|
|
enum class Platform(val desc: String) {
|
|
|
|
Windows32("windows32"), Windows64("windows64"), Linux32("linux32"), Linux64("linux64"), MacOS("mac");
|
|
|
|
}
|
|
|
|
|
|
|
|
class PackrConfig(
|
|
|
|
var platform: Platform? = null,
|
|
|
|
var jdk: String? = null,
|
|
|
|
var executable: String? = null,
|
|
|
|
var classpath: List<String>? = null,
|
|
|
|
var removePlatformLibs: List<String>? = null,
|
|
|
|
var mainClass: String? = null,
|
|
|
|
var vmArgs: List<String>? = null,
|
|
|
|
var minimizeJre: String? = null,
|
|
|
|
var cacheJre: File? = null,
|
|
|
|
var resources: List<File>? = null,
|
|
|
|
var outDir: File? = null,
|
|
|
|
var platformLibsOutDir: File? = null,
|
|
|
|
var iconResource: File? = null,
|
|
|
|
var bundleIdentifier: String? = null
|
|
|
|
)
|
|
|
|
|
|
|
|
for (platform in Platform.values()) {
|
2020-05-19 04:14:01 +07:00
|
|
|
val platformName = platform.toString()
|
|
|
|
|
|
|
|
tasks.create("packr${platformName}") {
|
2023-03-08 02:54:41 +07:00
|
|
|
// This task assumes that 'dist' has already been called - does not 'gradle depend' on it
|
|
|
|
// so we can run 'dist' from one job and then run the packr builds from a different job
|
2020-05-19 04:14:01 +07:00
|
|
|
|
2021-09-10 16:39:15 +07:00
|
|
|
// Needs to be here and not in doLast because the zip task depends on the outDir
|
|
|
|
val jarFile = "$rootDir/desktop/build/libs/${BuildConfig.appName}.jar"
|
|
|
|
val config = PackrConfig()
|
|
|
|
config.platform = platform
|
|
|
|
|
|
|
|
config.apply {
|
|
|
|
executable = "Unciv"
|
|
|
|
classpath = listOf(jarFile)
|
|
|
|
removePlatformLibs = config.classpath
|
|
|
|
mainClass = mainClassName
|
|
|
|
vmArgs = listOf("Xmx1G")
|
|
|
|
minimizeJre = "desktop/packrConfig.json"
|
|
|
|
outDir = file("packr")
|
|
|
|
}
|
|
|
|
|
2020-05-19 04:14:01 +07:00
|
|
|
doLast {
|
2021-08-23 01:08:26 +07:00
|
|
|
// https://gist.github.com/seanf/58b76e278f4b7ec0a2920d8e5870eed6
|
|
|
|
fun String.runCommand(workingDir: File) {
|
|
|
|
val process = ProcessBuilder(*split(" ").toTypedArray())
|
|
|
|
.directory(workingDir)
|
|
|
|
.redirectOutput(ProcessBuilder.Redirect.PIPE)
|
|
|
|
.redirectError(ProcessBuilder.Redirect.PIPE)
|
|
|
|
.start()
|
|
|
|
|
|
|
|
if (!process.waitFor(30, TimeUnit.SECONDS)) {
|
|
|
|
process.destroy()
|
|
|
|
throw RuntimeException("execution timed out: $this")
|
|
|
|
}
|
|
|
|
if (process.exitValue() != 0) {
|
|
|
|
throw RuntimeException("execution failed with code ${process.exitValue()}: $this")
|
|
|
|
}
|
|
|
|
println(process.inputStream.bufferedReader().readText())
|
|
|
|
}
|
|
|
|
|
2021-09-10 16:30:09 +07:00
|
|
|
|
2022-10-13 03:39:57 +07:00
|
|
|
if (config.outDir!!.exists()) delete(config.outDir)
|
2021-08-23 01:08:26 +07:00
|
|
|
|
2021-09-10 16:30:09 +07:00
|
|
|
// Requires that both packr and the jre are downloaded, as per buildAndDeploy.yml, "Upload to itch.io"
|
|
|
|
|
2022-10-13 03:39:57 +07:00
|
|
|
val jdkFile =
|
2021-09-10 16:30:09 +07:00
|
|
|
when (platform) {
|
2022-10-13 03:39:57 +07:00
|
|
|
Platform.Linux64 -> "jre-linux-64.tar.gz"
|
|
|
|
Platform.Windows64 -> "jdk-windows-64.zip"
|
2021-09-10 16:30:09 +07:00
|
|
|
else -> "jre-macOS.tar.gz"
|
|
|
|
}
|
|
|
|
|
2022-10-13 03:39:57 +07:00
|
|
|
val platformNameForPackrCmd =
|
|
|
|
if (platform == Platform.MacOS) "mac"
|
2024-01-31 01:17:51 +07:00
|
|
|
else platform.name.lowercase()
|
2021-09-10 16:30:09 +07:00
|
|
|
|
2022-10-13 03:39:57 +07:00
|
|
|
val command = "java -jar $rootDir/packr-all-4.0.0.jar" +
|
|
|
|
" --platform $platformNameForPackrCmd" +
|
|
|
|
" --jdk $jdkFile" +
|
|
|
|
" --executable Unciv" +
|
|
|
|
" --classpath $jarFile" +
|
|
|
|
" --mainclass $mainClassName" +
|
|
|
|
" --vmargs Xmx1G " +
|
|
|
|
" --output ${config.outDir}"
|
|
|
|
command.runCommand(rootDir)
|
2020-05-19 04:14:01 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
tasks.register<Zip>("zip${platformName}") {
|
2020-07-24 13:30:00 +07:00
|
|
|
archiveFileName.set("${BuildConfig.appName}-${platformName}.zip")
|
2020-05-19 04:14:01 +07:00
|
|
|
from(config.outDir)
|
2020-07-24 13:30:00 +07:00
|
|
|
destinationDirectory.set(deployFolder)
|
2020-05-19 04:14:01 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
finalizedBy("zip${platformName}")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
tasks.register<Zip>("zipLinuxFilesForJar") {
|
2020-07-24 13:30:00 +07:00
|
|
|
archiveFileName.set("linuxFilesForJar.zip")
|
2020-05-19 04:14:01 +07:00
|
|
|
from(file("linuxFilesForJar"))
|
2020-07-24 13:30:00 +07:00
|
|
|
destinationDirectory.set(deployFolder)
|
2021-12-23 00:17:50 +07:00
|
|
|
}
|