-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathbuild.gradle.kts
94 lines (80 loc) · 3.34 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
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
plugins {
kotlin("jvm") version "1.9.0"
id("com.github.johnrengelman.shadow") version "8.1.1"
`maven-publish`
}
group = "cf.wayzer"
version = System.getenv().getOrDefault("VERSION", "3.0-SNAPSHOT")
repositories {
mavenCentral()
maven(url = "https://www.jitpack.io")
}
dependencies {
implementation(kotlin("stdlib"))
compileOnly("com.github.Anuken.Arc:arc-core:v146")
compileOnly("com.github.anuken.mindustryjitpack:core:v145") {
exclude(group = "com.github.Anuken.Arc")
}
}
kotlin {
jvmToolchain(8)
}
publishing {
publications {
create<MavenPublication>("maven") {
groupId = rootProject.group.toString()
artifactId = project.name
version = rootProject.version.toString()
from(components["kotlin"])
}
}
}
tasks.withType<ProcessResources> {
inputs.property("version", rootProject.version)
filter(
filterType = org.apache.tools.ant.filters.ReplaceTokens::class,
properties = mapOf("tokens" to mapOf("version" to rootProject.version))
)
}
val shadowTask: ShadowJar = tasks.withType(ShadowJar::class.java) {
configurations = listOf(project.configurations.runtimeClasspath.get())
minimize()
}.first()
val jarAndroid = tasks.create("jarAndroid") {
dependsOn(shadowTask)
val inFile = shadowTask.archiveFile.get().asFile
val outFile = inFile.resolveSibling("${shadowTask.archiveBaseName.get()}-Android.jar")
outputs.file(outFile)
doLast {
val sdkRoot = System.getenv("ANDROID_HOME") ?: System.getenv("ANDROID_SDK_ROOT")
if (sdkRoot == null || !File(sdkRoot).exists()) throw GradleException("No valid Android SDK found. Ensure that ANDROID_HOME is set to your Android SDK directory.")
val d8Tool = File("$sdkRoot/build-tools/").listFiles()?.sortedDescending()
?.flatMap { dir -> (dir.listFiles().orEmpty()).filter { it.name.startsWith("d8") } }?.firstOrNull()
?: throw GradleException("No d8 found. Ensure that you have an Android platform installed.")
val platformRoot = File("$sdkRoot/platforms/").listFiles()?.sortedDescending()?.firstOrNull { it.resolve("android.jar").exists() }
?: throw GradleException("No android.jar found. Ensure that you have an Android platform installed.")
//collect dependencies needed for desugaring
val dependencies = (configurations.compileClasspath.get() + configurations.runtimeClasspath.get() + platformRoot.resolve("android.jar"))
.joinToString(" ") { "--classpath ${it.path}" }
exec {
commandLine("$d8Tool $dependencies --min-api 14 --output $outFile $inFile".split(" "))
workingDir(inFile.parentFile)
standardOutput = System.out
errorOutput = System.err
}.assertNormalExitValue()
}
}
tasks.create("devInstall", Copy::class.java) {
dependsOn(shadowTask)
from(shadowTask.archiveFile.get())
into(System.getenv("AppData") + "/mindustry/mods")
}
tasks.create("dist", Jar::class.java) {
dependsOn(shadowTask)
dependsOn(jarAndroid)
from(zipTree(shadowTask.archiveFile.get()))
from(zipTree(jarAndroid.outputs.files.first()))
destinationDirectory.set(buildDir.resolve("dist"))
archiveFileName.set("ContentsTweaker-${rootProject.version}.jar")
}