-
Notifications
You must be signed in to change notification settings - Fork 2
/
build.gradle.kts
335 lines (285 loc) · 13.2 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
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
import com.loadingbyte.cinecred.*
import com.loadingbyte.cinecred.Platform
import org.apache.tools.ant.filters.ReplaceTokens
import org.gradle.configurationcache.extensions.capitalized
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
import java.util.*
plugins {
kotlin("jvm") version "1.9.0"
}
group = "com.loadingbyte"
version = "1.5.1"
val jdkVersion = 17
val slf4jVersion = "2.0.7"
val poiVersion = "5.2.3"
val batikVersion = "1.16"
val javacppVersion = "1.5.8"
val ffmpegVersion = "5.1.2-$javacppVersion"
val javaProperties = Properties().apply { file("java.properties").reader().use(::load) }
val mainClass = javaProperties.getProperty("mainClass")!!
val addModules = javaProperties.getProperty("addModules").split(' ')
val addOpens = javaProperties.getProperty("addOpens").split(' ')
val splashScreen = javaProperties.getProperty("splashScreen")!!
val javaOptions = javaProperties.getProperty("javaOptions")!!
sourceSets {
register("demo") {
compileClasspath += sourceSets.main.get().output
runtimeClasspath += sourceSets.main.get().output
}
}
java {
toolchain.languageVersion.set(JavaLanguageVersion.of(jdkVersion))
}
val natives by configurations.creating
val implementationAndNatives by configurations.creating {
configurations.implementation.get().extendsFrom(this)
natives.extendsFrom(this)
}
val demoImplementation by configurations.getting { extendsFrom(configurations.implementation.get()) }
val demoRuntimeOnly by configurations.getting { extendsFrom(configurations.runtimeOnly.get()) }
repositories {
mavenCentral()
}
dependencies {
implementation("org.jetbrains.kotlinx", "kotlinx-collections-immutable", "0.3.5")
// Log to java.util.logging
implementation("org.slf4j", "slf4j-jdk14", slf4jVersion)
// Redirect other logging frameworks to slf4j.
// Batik & PDFBox use Jakarta Commons Logging. POI uses log4j2.
implementation("org.slf4j", "jcl-over-slf4j", slf4jVersion)
implementation("org.apache.logging.log4j", "log4j-to-slf4j", "2.20.0")
// Spreadsheet IO
implementation("org.apache.poi", "poi", poiVersion)
implementation("org.apache.poi", "poi-ooxml", poiVersion)
implementation("com.github.miachm.sods", "SODS", "1.6.1")
implementation("org.apache.commons", "commons-csv", "1.10.0")
// Spreadsheet Services
implementation("com.googlecode.plist", "dd-plist", "1.27")
implementation("com.google.oauth-client", "google-oauth-client-jetty", "1.34.1")
implementation("com.google.apis", "google-api-services-sheets", "v4-rev20230227-2.0.0")
// Raster Image IO
implementation("com.twelvemonkeys.imageio", "imageio-tga", "3.9.4")
// SVG IO
implementation("org.apache.xmlgraphics", "batik-bridge", batikVersion)
implementation("org.apache.xmlgraphics", "batik-svggen", batikVersion)
// For pictures embedded in the SVG:
implementation("org.apache.xmlgraphics", "batik-codec", batikVersion)
// PDF IO
implementation("org.apache.pdfbox", "pdfbox", "2.0.28")
implementation("de.rototor.pdfbox", "graphics2d", "0.42")
// Video IO
implementation("org.bytedeco", "javacpp", javacppVersion)
implementation("org.bytedeco", "ffmpeg", ffmpegVersion)
for (platform in Platform.values()) {
natives("org.bytedeco", "javacpp", javacppVersion, classifier = platform.slugDeps)
natives("org.bytedeco", "ffmpeg", ffmpegVersion, classifier = "${platform.slugDeps}-gpl")
}
// UI
implementation("com.miglayout", "miglayout-swing", "11.1")
implementationAndNatives("com.formdev", "flatlaf", "3.1.1")
implementation("org.commonmark", "commonmark", "0.21.0")
// Testing
testImplementation("org.junit.jupiter", "junit-jupiter", "5.9.3")
}
configurations.configureEach {
// POI:
// We don't re-evaluate formulas, and as only that code calls Commons Math, we can omit the dependency.
exclude("org.apache.commons", "commons-math3")
// This is only required for adding pictures to workbooks via code, which we don't do.
exclude("commons-codec", "commons-codec")
// Batik & PDFBox: We replace this commons-logging dependency by the slf4j bridge.
exclude("commons-logging", "commons-logging")
// Batik:
// The Java XML APIs are part of the JDK itself since Java 5.
exclude("xml-apis", "xml-apis")
// Batik functions well without the big xalan dependency.
exclude("xalan", "xalan")
}
tasks.withType<JavaCompile>().configureEach {
options.release.set(jdkVersion)
options.compilerArgs = listOf("--add-modules") + addModules
}
tasks.withType<KotlinCompile>().configureEach {
kotlinOptions.jvmTarget = jdkVersion.toString()
}
tasks.test {
useJUnitPlatform()
}
val writeVersionFile by tasks.registering(WriteFile::class) {
text.set(version.toString())
outputFile.set(layout.buildDirectory.file("generated/version/version"))
}
val drawSplash by tasks.registering(DrawSplash::class) {
version.set(project.version.toString())
logoFile.set(mainResource("logo.svg"))
reguFontFile.set(mainResource("fonts/Titillium-RegularUpright.otf"))
semiFontFile.set(mainResource("fonts/Titillium-SemiboldUpright.otf"))
outputFile.set(layout.buildDirectory.file("generated/splash/splash.png"))
}
val collectPOMLicenses by tasks.registering(CollectPOMLicenses::class) {
configuration.set(configurations.runtimeClasspath)
outputDir.set(layout.buildDirectory.dir("generated/licenses"))
}
tasks.processResources {
from(writeVersionFile)
from(drawSplash)
from("CHANGELOG.md")
into("licenses") {
from("LICENSE")
rename("LICENSE", "Cinecred-LICENSE")
}
// Collect all licenses (and related files) from the dependencies.
// Rename these files such that each one carries the name of the JAR it originated from.
for (dep in configurations.runtimeClasspath.get().resolvedConfiguration.resolvedArtifacts)
from(zipTree(dep.file)) {
include(listOf("COPYRIGHT", "LICENSE", "NOTICE", "README").map { "**/*$it*" })
eachFile { path = "licenses/libraries/${dep.name}-${file.nameWithoutExtension}" }
includeEmptyDirs = false
}
into("licenses/libraries") {
from(collectPOMLicenses)
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
}
}
val platformNativesTasks = Platform.values().associateWith { platform ->
tasks.register<Sync>("${platform.label}Natives") {
// Collect all natives for the platform in a single directory
from(layout.projectDirectory.dir("src/main/natives/${platform.slug}"))
for (dep in natives.resolvedConfiguration.resolvedArtifacts)
from(zipTree(dep.file)) {
include("**/*${platform.slugDeps}*/**/*.${platform.os.nativesExt}*")
include("**/*${platform.slugDeps}*.${platform.os.nativesExt}*")
exclude("**/*avdevice*", "**/*avfilter*", "**/*postproc*")
}
into(layout.buildDirectory.dir("natives/${platform.slug}"))
eachFile { path = name }
includeEmptyDirs = false
}
}
for (platform in Platform.values()) {
val platformNatives = platformNativesTasks.getValue(platform)
val mainClass_ = mainClass
val jvmArgs_ = listOf(
"-Djava.library.path=${platformNatives.get().destinationDir}",
"-splash:${tasks.processResources.get().destinationDir}/$splashScreen",
"--add-modules", addModules.joinToString(",")
) + addOpens.flatMap { listOf("--add-opens", "$it=ALL-UNNAMED") } + javaOptions.split(" ")
tasks.register<JavaExec>("runOn${platform.label.capitalized()}") {
group = "Execution"
description = "Runs the program on ${platform.label.capitalized()}."
dependsOn(platformNatives)
classpath(sourceSets.main.map { it.runtimeClasspath })
mainClass.set(mainClass_)
jvmArgs = jvmArgs_
}
tasks.register<JavaExec>("runDemoOn${platform.label.capitalized()}") {
group = "Execution"
description = "Runs the demo on ${platform.label.capitalized()}."
dependsOn(platformNatives)
classpath(sourceSets.named("demo").map { it.runtimeClasspath })
mainClass.set("com.loadingbyte.cinecred.DemoMain")
jvmArgs = jvmArgs_
}
}
val drawOSImagesTasks = Platform.OS.values().associateWith { os ->
// Draw the images that are needed for the OS.
tasks.register<DrawImages>("draw${os.slug.capitalized()}Images") {
version.set(project.version.toString())
forOS.set(os)
logoFile.set(mainResource("logo.svg"))
semiFontFile.set(mainResource("fonts/Titillium-SemiboldUpright.otf"))
boldFontFile.set(mainResource("fonts/Titillium-BoldUpright.otf"))
outputDir.set(layout.buildDirectory.dir("generated/packaging/${os.slug}"))
}
}
val preparePlatformPackagingTasks = Platform.values().map { platform ->
// Collect all files needed for packaging in a folder.
val preparePlatformPackaging = tasks.register<Sync>("prepare${platform.label.capitalized()}Packaging") {
doFirst {
if (!Regex("\\d+\\.\\d+\\.\\d+").matches(version.toString()))
throw GradleException("Non-release versions cannot be packaged.")
}
group = "Packaging Preparation"
description = "Prepares files for building a ${platform.label.capitalized()} package on that platform."
into(layout.buildDirectory.dir("packaging/${platform.slug}"))
// Copy the packaging scripts and fill in some variables. Note that we
// don't select the scripts by platform here because that's not worth the effort.
from("packaging") {
val mainJarName = tasks.jar.get().archiveFileName.get()
val tokens = mapOf(
"VERSION" to version,
"MAIN_JAR" to mainJarName,
"MAIN_CLASS" to mainClass,
"JAVA_OPTIONS" to "-Djava.library.path=\$APPDIR" +
" --add-modules ${addModules.joinToString(",")} " +
addOpens.joinToString(" ") { "--add-opens $it=ALL-UNNAMED" } +
" -splash:\$APPDIR/$splashScreen $javaOptions",
"OS" to platform.os.slug,
"ARCH" to platform.arch.slug,
"ARCH_TEMURIN" to platform.arch.slugTemurin,
"ARCH_WIX" to platform.arch.slugWix,
"ARCH_DEBIAN" to platform.arch.slugDebian,
"DESCRIPTION" to "Create beautiful film credits without the pain",
"DESCRIPTION_DE" to "Wunderschöne Filmabspänne schmerzfrei erstellen",
"DESCRIPTION_ZH_CN" to "高效简洁且功能多样的电影片尾字幕处理方案",
"URL" to "https://cinecred.com",
"VENDOR" to "Felix Mujkanovic",
"EMAIL" to "felix@cinecred.com",
"LEGAL_PATH_RUNTIME" to when (platform.os) {
Platform.OS.WINDOWS -> "runtime\\legal"
Platform.OS.MAC -> "runtime/Contents/Home/legal"
Platform.OS.LINUX -> "lib/runtime/legal"
},
"LEGAL_PATH_APP" to when (platform.os) {
Platform.OS.WINDOWS -> "app\\$mainJarName"
Platform.OS.MAC -> "app/$mainJarName"
Platform.OS.LINUX -> "lib/app/$mainJarName"
}
)
filter<ReplaceTokens>("tokens" to tokens)
}
into("app") {
from(tasks.jar)
from(configurations.runtimeClasspath)
from(platformNativesTasks[platform])
from(tasks.processResources.map { it.destDirProvider.file(splashScreen) })
}
into("images") {
from(drawOSImagesTasks[platform.os])
}
}
return@map preparePlatformPackaging
}
val preparePackaging by tasks.registering {
group = "Packaging Preparation"
description = "For each platform, prepares files for building a package for that platform on that platform."
dependsOn(preparePlatformPackagingTasks)
}
val mergeServices by tasks.registering(MergeServices::class) {
configuration.set(configurations.runtimeClasspath)
outputDir.set(layout.buildDirectory.dir("generated/allJar/services"))
}
val allJar by tasks.registering(Jar::class) {
group = "Build"
description = "Assembles a jar archive containing the program classes and all dependencies, excluding natives."
archiveClassifier.set("all")
manifest.attributes(
"Main-Class" to mainClass,
"SplashScreen-Image" to splashScreen,
"Add-Opens" to addOpens.joinToString(" ")
)
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
from(sourceSets.main.map { it.output })
for (dep in configurations.runtimeClasspath.get().resolvedConfiguration.resolvedArtifacts)
from(zipTree(dep.file)) {
exclude("META-INF/**", "**/module-info.class")
}
into("META-INF/services") {
from(mergeServices)
}
}
fun mainResource(path: String): Provider<RegularFile> =
sourceSets.main.map { layout.projectDirectory.file(it.resources.matching { include("/$path") }.singleFile.path) }
// We need to retrofit this property in a hacky and not entirely compliant way because it's sadly not migrated yet.
val Copy.destDirProvider: Directory
get() = layout.projectDirectory.dir(destinationDir.path)