generated from Anuken/MindustryKotlinModTemplate
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.gradle.kts
More file actions
121 lines (101 loc) · 3.98 KB
/
build.gradle.kts
File metadata and controls
121 lines (101 loc) · 3.98 KB
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
// 关于我从啥都不会,到6小时速通 Gradle Kotlin DSL 这件事
buildscript {
repositories {
mavenLocal()
mavenCentral()
maven { url = uri("https://raw.githubusercontent.com/Zelaux/MindustryRepo/master/repository") }
maven { url = uri("https://www.jitpack.io") }
}
val kotlinVersion = "2.0.0"
dependencies {
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:${kotlinVersion}")
}
}
group = "meow0x7e"
version = "v0.2.3"
val mindustryVersion = "v146"
val jabelVersion = "93fde537c7"
val sdkHome: String = System.getenv("ANDROID_HOME")
?: System.getenv("ANDROID_SDK_ROOT")
?: "${System.getenv("HOME")}/Android/Sdk"
plugins {
kotlin("jvm") version ("2.0.0") apply true
}
repositories {
mavenLocal()
mavenCentral()
maven { url = uri("https://raw.githubusercontent.com/Zelaux/MindustryRepo/master/repository") }
maven { url = uri("https://www.jitpack.io") }
}
dependencies {
api(kotlin("stdlib", "2.0.0"))
compileOnly("com.github.Anuken.Arc:arc-core:${mindustryVersion}")
compileOnly("com.github.Anuken.Mindustry:core:${mindustryVersion}")
//implementation("com.github.liplum:MultiCrafterLib:v1.8")
annotationProcessor("com.github.Anuken:jabel:$jabelVersion")
}
java {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}
sourceSets {
main {
java {
srcDirs("src")
}
}
}
val jar = tasks.jar.get()
tasks.withType<Jar> {
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
archiveFileName.set("${project.name}-${project.version}-Desktop.jar")
from(configurations.runtimeClasspath.get().toList()
.map { if (it.isDirectory) it else zipTree(it) })
from(rootDir) { include("LICENSE", "mod.hjson") }
from("assets/") { include("**") }
}
tasks.register("jarAndroid") {
dependsOn("jar")
doLast {
if (!File(sdkHome).exists()) throw GradleException("No valid Android SDK found. Ensure that ANDROID_HOME is set to your Android SDK directory.")
val platformRoot =
File("${sdkHome}/platforms/").listFiles()?.find { File(it!!, "android.jar").exists() }
?: throw GradleException("No android.jar found. Ensure that you have an Android platform installed.")
val buildToolRoot =
File("${sdkHome}/build-tools/").listFiles()?.find { File(it, "d8").exists() }
?: throw GradleException("No d8 found. Ensure that you have an Android build-tool installed.")
//dex and desugar files - this requires d8 in your PATH
project.exec {
commandLine(ArrayList<String>().apply {
add(File(buildToolRoot, "d8").absolutePath)
//collect dependencies needed for desugaring
addAll(listOf(
*configurations.compileClasspath.get().toList().toTypedArray(),
*configurations.runtimeClasspath.get().toList().toTypedArray(),
File(platformRoot, "android.jar")
).flatMap {
listOf("--classpath", it.absolutePath)
})
add("--min-api")
add("14")
add("--output")
add("${project.name}-${project.version}-Android.jar")
add("${project.name}-${project.version}-Desktop.jar")
})
workingDir = File("${buildDir}/libs/")
}
}
}
tasks.register("deploy", Jar::class) {
dependsOn(tasks.getByName("jarAndroid"), "jar")
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
archiveFileName.set("${project.name}-${project.version}.jar")
from(
zipTree("${buildDir}/libs/${project.name}-${project.version}-Desktop.jar"),
zipTree("${buildDir}/libs/${project.name}-${project.version}-Android.jar")
)
doLast {
delete("${buildDir}/libs/${project.name}-${project.version}-Desktop.jar")
delete("${buildDir}/libs/${project.name}-${project.version}-Android.jar")
}
}