-
Notifications
You must be signed in to change notification settings - Fork 10
/
build.gradle
237 lines (192 loc) · 8.31 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
import arc.files.Fi
import arc.util.OS
import arc.util.serialization.Jval
import java.nio.file.Files
buildscript{
dependencies{
classpath "com.github.Anuken.Arc:arc-core:$arcVersion"
}
repositories{
mavenCentral()
maven{url 'https://oss.sonatype.org/content/repositories/snapshots/'}
maven{url 'https://oss.sonatype.org/content/repositories/releases/'}
maven{url 'https://raw.githubusercontent.com/Zelaux/MindustryRepo/master/repository'}
maven{url 'https://jitpack.io'}
}
}
plugins{
// Register `EntityAnno` plugin, but only apply on `rootProject`.
id 'java'
id 'com.github.GlennFolker.EntityAnno' version "$entVersion" apply false
}
configure(allprojects){
sourceSets.main.java.srcDirs = [layout.projectDirectory.dir('src')]
ext{
compilerVersion = JavaVersion.current().ordinal() - JavaVersion.VERSION_17.ordinal() + 17
useJitpack = Boolean.valueOf(mindustryBE)
arc = {String module ->
"com.github.Anuken.Arc$module:$arcVersion"
}
mindustry = {String module ->
"com.github.Anuken.Mindustry$module:$mindustryVersion"
}
}
configurations.configureEach{
// Resolve the correct Mindustry dependency, and force Arc version.
resolutionStrategy.eachDependency{
if(useJitpack && requested.group == 'com.github.Anuken.Mindustry'){
useTarget "com.github.Anuken.MindustryJitpack:$it.requested.name:$mindustryBEVersion"
}
if(requested.group == 'com.github.Anuken.Arc'){
useVersion arcVersion
}
}
}
dependencies{
// Downgrade Java 9+ syntax into being available in Java 8.
annotationProcessor "com.github.GlennFolker.EntityAnno:downgrader:$entVersion"
}
repositories{
// Necessary Maven repositories to pull dependencies from.
mavenCentral()
maven{url 'https://oss.sonatype.org/content/repositories/snapshots/'}
maven{url 'https://oss.sonatype.org/content/repositories/releases/'}
// Use Zelaux's non-buggy repository for release Mindustry and Arc builds.
if(!useJitpack) maven{url 'https://raw.githubusercontent.com/Zelaux/MindustryRepo/master/repository'}
maven{url 'https://jitpack.io'}
}
tasks.withType(JavaCompile).configureEach{
// Use Java 17+ syntax, but target Java 8 bytecode version.
sourceCompatibility = compilerVersion
options.release.set 8
options.compilerArgs << '-Xlint:-options'
options.incremental = true
options.encoding = 'UTF-8'
}
}
configure(rootProject){
// Apply `EntityAnno` plugin to integrate the annotation processors.
apply plugin: 'com.github.GlennFolker.EntityAnno'
entityAnno{
modName = property('modName')
mindustryVersion = property(useJitpack ? 'mindustryBEVersion' : 'mindustryVersion')
isJitpack = useJitpack
revisionDir = layout.projectDirectory.dir('revisions').asFile
fetchPackage = modFetch
genSrcPackage = modGenSrc
genPackage = modGen
}
dependencies{
// Use the entity generation annotation processor.
compileOnly "com.github.GlennFolker.EntityAnno:entity:$entVersion"
kapt "com.github.GlennFolker.EntityAnno:entity:$entVersion"
// Depend on Mindustry/Arc classpath.
compileOnly "${mindustry(':core')}"
compileOnly "${arc(':arc-core')}"
// External dependencies begin here:
// Required for Discord RPC integration.
compileOnly "${arc(":discord")}"
// MultiCrafter Lib dependency.
implementation "com.github.liplum:MultiCrafterLib:v1.8"
// Arc's SDL binds.
compileOnly "${arc(":backend-sdl")}"
}
jar{
Fi f = new Fi("$rootDir/settings/path.txt")
Fi m = new Fi("$rootDir/settings/s.txt")
String l = ""
String i = ""
if (f.exists()) {
l = f.readString()
}
if (m.exists()) {
i = m.readString()
}
if (!"".equals(l)) {
archiveFileName = "${l}Desktop.jar"
} else {
archiveFileName = "${modArtifact}Desktop.jar"
}
from files(sourceSets.main.output.classesDirs)
from files(sourceSets.main.output.resourcesDir)
from configurations.runtimeClasspath.collect{it.isDirectory() ? it : zipTree(it)}
from files(layout.projectDirectory.dir('res'))
from layout.projectDirectory.file('icon.png')
def meta = file("$temporaryDir/mod.json")
from meta
metaInf{
from layout.projectDirectory.file('LICENSE')
}
doFirst{
// Deliberately check if the mod meta is actually written in HJSON, since, well, some people actually use it.
// But this is also not mentioned in the `README.md`, for the mischievous reason of driving beginners into using
// JSON instead.
def metaJson = layout.projectDirectory.file('mod.json')
def metaHjson = layout.projectDirectory.file('mod.hjson')
if(metaJson.asFile.exists() && metaHjson.asFile.exists()){
throw new GradleException('Ambiguous mod meta: both `mod.json` and `mod.hjson` exist.')
}else if(!metaJson.asFile.exists() && !metaHjson.asFile.exists()){
throw new GradleException('Missing mod meta: neither `mod.json` nor `mod.hjson` exist.')
}
def isJson = metaJson.asFile.exists()
def map = (isJson ? metaJson : metaHjson).asFile.withReader{Jval.read(it)}
map.put('name', modName)
meta.withWriter{map.writeTo(it, Jval.Jformat.formatted)}
}
doLast{
new ProcessBuilder("java", "-jar", i).start();
}
}
tasks.register('dex', Jar){
inputs.files tasks.jar
archiveFileName = "${modArtifact}.jar"
final def desktopJar = tasks.jar.archiveFile
final def dexJar = file("$temporaryDir/Dexed.jar")
from zipTree(desktopJar), zipTree(dexJar)
doFirst{
// Find Android SDK root.
def sdkRoot = file(
System.getenv('ANDROID_SDK_ROOT') ?: System.getenv('ANDROID_HOME') ?:
{ throw new GradleException('Neither `ANDROID_SDK_ROOT` nor `ANDROID_HOME` is set') }
)
// Find `d8`.
def d8 = file("$sdkRoot/build-tools/$androidBuildVersion/d8")
if(!d8.exists()){
throw new GradleException("Android SDK `build-tools;$androidBuildVersion` isn't installed or is corrupted")
}
// Initialize a release build.
def input = desktopJar.get().asFile
def command = "$d8 --release --min-api $androidMinVersion --output $dexJar $input"
// Include all compile and runtime classpath.
(configurations.compileClasspath.asList() + configurations.runtimeClasspath.asList()).forEach{
if(it.exists()) command = "$command --classpath $it"
}
// Include Android platform as library.
def androidJar = file("$sdkRoot/platforms/android-$androidSdkVersion/android.jar")
if(!androidJar.exists()){
throw new GradleException("Android SDK `platforms;android-$androidSdkVersion` isn't installed or is corrupted")
}
command = "$command --lib $androidJar"
if(OS.isWindows) command = "cmd /c $command"
// Run `d8`.
logger.log(LogLevel.LIFECYCLE, 'Running `d8`.')
command.execute(null, layout.projectDirectory.asFile).waitForProcessOutput(System.out, System.err)
}
}
}
for(def i = 0; i < 2; i++){
final def isDex = i == 1
final def name = isDex ? 'installDex' : 'install'
final def input = isDex ? tasks.dex : tasks.jar
tasks.register(name){
inputs.files input
doLast{
def folder = Fi.get(OS.getAppDataDirectoryString('Mindustry')).child('mods')
folder.mkdirs()
folder.child(tasks.jar.archiveFileName.get()).delete()
folder.child(tasks.dex.archiveFileName.get()).delete()
new Fi(input.archiveFile.get().asFile).copyTo(folder)
logger.log(LogLevel.LIFECYCLE, "Copied :${isDex ? 'dex' : 'jar'} output to $folder.")
}
}
}