-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.gradle
249 lines (204 loc) · 8.52 KB
/
build.gradle
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
project.repositories {
mavenCentral()
mavenLocal()
maven { url "https://raw.githubusercontent.com/Zelaux/MindustryRepo/master/repository" }
maven{ url "https://raw.githubusercontent.com/Zelaux/Repo/master/repository" }
maven { url "https://www.jitpack.io" }
}
project.plugins.apply("java")
project.plugins.apply("idea")
project.plugins.apply("maven-publish")
ext {
var localFile = file("settings/local.json")
local = localFile.exists() ? new groovy.json.JsonSlurper().parseText(localFile.text) : null
var settingsFile = file("settings/settings.json")
settings = settingsFile.exists() ? new groovy.json.JsonSlurper().parseText(settingsFile.text) : null
project.group = project.ext.settings?.projectSettings?.group ?: "group"
project.version = project.ext.settings?.projectSettings?.version ?: "nil"
buildScriptExtensions = []
settings?.extensions?.each { String ext ->
project.file("extensions/$ext").listFiles()?.each { File file ->
buildScriptExtensions += file
}
}
doExec = { String cmd ->
cmd.execute(null, rootProject.projectDir).waitForProcessOutput(System.out, System.err)
}
getOutputJar = { Project p ->
return "Sueno.jar"
}
child = { File p, String c ->
return new File(p, c)
}
// parse dependencies
deps = [:]
var depsConf = project.ext.settings?.dependencies
var depsList = [:]
depsConf?.list?.each { dep ->
var k = dep.keySet()[0]
var v = dep[k]
depsList[k] = v
}
depsConf?.deps?.each { depType ->
k = depType.key
depType.value.each { String v ->
var dep = null
if (v.startsWith("project:")) {
dep = project.project(v.substring(8))
} else if (v.startsWith("list:")) {
dep = depsList[v.substring(5)]
} else if (v.startsWith("direct:")) {
dep = v.substring(7)
}
if (dep == null)
project.logger.log(LogLevel.ERROR, "Uncknown depedency type $v")
else {
if (!project.ext.deps.containsKey(k)) {
project.ext.deps[k] = []
}
project.ext.deps[k] += dep
}
}
}
// find sdkRoot in configs
var root = System.getenv("ANDROID_HOME") ?: System.getenv("ANDROID_SDK_ROOT") ?: project.ext.local?.jvm?.home
sdkRoot = (root == null ? null : new File(root))
dexFile = project.ext.child(project.buildDir, "dex.jar")
var ua = project.ext.local?.build?.buildAndroid
useandroid = ((ua == null) || ua)
}
project.tasks.create("fixNames") {
doLast {
project.sourceSets.main.resources.srcDirs.each { File dir ->
if (dir.exists()) {
dir.eachFileRecurse(groovy.io.FileType.FILES) { File file ->
if (file.name.endsWith(".hjson") || file.name.endsWith(".properties"))
file.write file.text.replaceAll("mm-", "mdvlm-")
}
}
}
}
}
project.group = project.ext.settings?.projectSettings?.group ?: "group"
project.version = project.ext.settings?.projectSettings?.version ?: "nil"
// src - java sources
// gen - generated java sources
// res - resources (e.g. assets)
project.sourceSets.main.java.srcDirs = [
"src", "gen"
]
project.sourceSets.main.resources.srcDirs = [
"res"
]
project.tasks.create("dex")
project.tasks.create("buildRelease", Jar)
project.tasks.create("copyBuildRelease")
project.tasks.compileJava { JavaCompile task ->
task.options.encoding = "UTF-8"
task.options.compilerArgs += "-Xlint:none"
task.options.generatedSourceOutputDirectory.set(project.file("gen"))
task.options.compilerArgs += ['--release', '8']
task.targetCompatibility = JavaVersion.VERSION_1_8
task.sourceCompatibility = JavaVersion.VERSION_20
task.options.forkOptions.jvmArgs += [
"--add-opens=jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED",
"--add-opens=jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED",
"--add-opens=jdk.compiler/com.sun.tools.javac.model=ALL-UNNAMED",
"--add-opens=jdk.compiler/com.sun.tools.javac.processing=ALL-UNNAMED",
"--add-opens=jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED",
"--add-opens=jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED",
"--add-opens=jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED",
"--add-opens=jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED",
"--add-opens=jdk.compiler/com.sun.tools.javac.main=ALL-UNNAMED",
"--add-opens=jdk.compiler/com.sun.tools.javac.jvm=ALL-UNNAMED",
"--add-opens=jdk.compiler/com.sun.tools.javac.comp=ALL-UNNAMED",
"--add-opens=java.base/sun.reflect.annotation=ALL-UNNAMED"
]
doFirst {
delete options.generatedSourceOutputDirectory.get().asFile.listFiles()
}
}
project.dependencies {
annotationProcessor "com.github.Anuken:jabel:93fde537c7"
if (project.ext.deps.implementation != null)
implementation project.ext.deps.implementation
if (project.ext.deps.api != null)
api project.ext.deps.api
if (project.ext.deps.compileOnly != null)
compileOnly project.ext.deps.compileOnly
if (project.ext.deps.annotationProcessor != null)
annotationProcessor project.ext.deps.annotationProcessor
}
project.tasks.copyBuildRelease { Task task ->
task.dependsOn project.tasks.buildRelease
task.doLast {
project.ext.local?.copy?.each { p ->
project.copy { CopySpec spec ->
spec.from project.tasks.buildRelease.archiveFile.get()
spec.into p
}
}
}
}
project.tasks.jar { Jar jar ->
jar.archiveFileName.set "classes.jar"
jar.duplicatesStrategy DuplicatesStrategy.EXCLUDE
jar.from {
project.configurations.runtimeClasspath.collect { File file ->
file.isDirectory() ? file : zipTree(file)
}
}
}
// collect classes and dex jars
project.tasks.buildRelease { Jar jar ->
jar.dependsOn project.tasks.dex
jar.dependsOn project.tasks.jar
jar.archiveFileName = project.ext.getOutputJar(project)
jar.from {
project.ext.useandroid ? [project.zipTree(project.tasks.jar.archiveFile.get()), project.zipTree(dexFile)] :
[project.zipTree(project.tasks.jar.archiveFile.get())]
}
jar.destinationDirectory.set project.file("artifacts")
}
// create dex jar
project.tasks.dex { Task task ->
task.dependsOn project.tasks.jar
// create dex jar
task.doLast {
// delete previous dex jar
if (project.ext.dexFile.exists())
project.delete project.ext.dexFile
println project.ext.useandroid ? "Building dex jar" : "Dex jar building skipped"
if (project.ext.useandroid) {
// find d8 and android.jar locations
if (project.ext.sdkRoot == null || !project.ext.sdkRoot.exists())
throw new GradleException("No Android SDK found.")
var platformRoot = project.ext.child(project.ext.sdkRoot, "platforms").listFiles().find { File file ->
project.ext.child(file, "android.jar").exists()
}
String d8Name = System.getenv("OS") == "Windows_NT" ? "d8.bat" : "d8"
var buildToolsRoot = project.ext.child(project.ext.sdkRoot, "build-tools").listFiles().find { File file ->
project.ext.child(file, d8Name).exists()
}
if (!platformRoot || !buildToolsRoot)
throw new GradleException("" +
(!platformRoot ? "No android.jar found. Ensure that you have an Android platform installed." : "") +
(!buildToolsRoot ? "No $d8Name found. Ensure that you have an Android build tools installed." : ""))
// collect all classpath
var classpath = (configurations.compileClasspath.asList()
+ configurations.runtimeClasspath.asList()
+ project.ext.child(platformRoot, "android.jar"))
var dependencies = ""
for (path in classpath) {
dependencies += "--classpath $path.absolutePath "
}
// run d8
project.ext.doExec(
"$buildToolsRoot/$d8Name $dependencies ${project.tasks.jar.archiveFile.get()}" +
" --min-api 14 --output $dexFile.absolutePath")
}
}
}
project.ext.buildScriptExtensions?.each { File file ->
project.apply(from: file)
}