-
Notifications
You must be signed in to change notification settings - Fork 1.6k
/
build.gradle.kts
223 lines (186 loc) · 7.49 KB
/
build.gradle.kts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
import com.unciv.build.BuildConfig
import com.unciv.build.BuildConfig.gdxVersion
import com.unciv.build.BuildConfig.appVersion
import io.github.fourlastor.construo.Target
plugins {
id("kotlin")
id("io.github.fourlastor.construo") version "1.2.0"
}
sourceSets {
main {
java.srcDir("src/")
}
}
kotlin {
jvmToolchain(17)
target {
compilations.all {
kotlinOptions.jvmTarget = JavaVersion.VERSION_1_8.toString()
}
}
}
java {
targetCompatibility = JavaVersion.VERSION_1_8
}
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")
}
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"))
mainClass.set(mainClassName)
classpath = sourceSets.main.get().runtimeClasspath
standardInput = System.`in`
workingDir = assetsDir
isIgnoreExitValue = true
}
tasks.register<JavaExec>("debug") {
dependsOn(tasks.getByName("classes"))
mainClass.set(mainClassName)
classpath = sourceSets.main.get().runtimeClasspath
standardInput = System.`in`
workingDir = assetsDir
isIgnoreExitValue = true
debug = true
}
tasks.jar { // Compiles the jar file
dependsOn(tasks.getByName("classes"))
// META-INF/INDEX.LIST and META-INF/io.netty.versions.properties are duplicated, but I don't know why
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
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
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) }})
from(files(assetsDir))
exclude("mods", "SaveFiles", "MultiplayerFiles", "GameSettings.json", "lasterror.txt")
// This is for the .dll and .so files to make the Discord RPC work on all desktops
from(files(discordDir))
archiveFileName.set("${BuildConfig.appName}.jar")
manifest {
attributes(mapOf("Main-Class" to mainClassName, "Specification-Version" to appVersion))
}
}
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
)
val jarFile = "$rootDir/desktop/build/libs/${BuildConfig.appName}.jar"
construo {
// Construo fields should have docs
// name of the executable
name.set(BuildConfig.appName.lowercase())
// human-readable name, used for example in the `.app` name for macOS
humanName.set(BuildConfig.appName)
// Optional, defaults to project version
version.set(appVersion)
// Optional, defaults to application.mainClass or jar task main class
mainClass.set(mainClassName)
// Optional, defaults to $buildDir/construo/dist
// where to put the packaged zips
outputDir.set(deployFolder)
jlink {
// add arbitrary modules to be included when running jlink
modules.addAll("jdk.crypto.ec")
}
targets{
create<Target.MacOs>("macM1") {
architecture.set(Target.Architecture.AARCH64)
jdkUrl.set("https://github.com/adoptium/temurin17-binaries/releases/download/jdk-17.0.11%2B9/OpenJDK17U-jdk_aarch64_mac_hotspot_17.0.11_9.tar.gz")
// macOS needs an identifier
identifier.set(BuildConfig.identifier)
// Optional: icon for macOS
// macIcon.set(project.file("path/to/mac-icon.icns"))
}
}
}
for (platform in Platform.values()) {
val platformName = platform.toString()
tasks.create("packr${platformName}") {
// 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
// Needs to be here and not in doLast because the zip task depends on the outDir
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")
}
doLast {
// 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())
}
if (config.outDir!!.exists()) delete(config.outDir)
// Requires that both packr and the jre are downloaded, as per buildAndDeploy.yml, "Upload to itch.io"
val jdkFile =
when (platform) {
Platform.Linux64 -> "jre-linux-64.tar.gz"
Platform.Windows64 -> "jdk-windows-64.zip"
else -> "jre-macOS.tar.gz"
}
val platformNameForPackrCmd =
if (platform == Platform.MacOS) "mac"
else platform.name.lowercase()
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)
}
tasks.register<Zip>("zip${platformName}") {
archiveFileName.set("${BuildConfig.appName}-${platformName}.zip")
from(config.outDir)
destinationDirectory.set(deployFolder)
}
finalizedBy("zip${platformName}")
}
}
tasks.register<Zip>("zipLinuxFilesForJar") {
archiveFileName.set("linuxFilesForJar.zip")
from(file("linuxFilesForJar"))
destinationDirectory.set(deployFolder)
}