forked from Anuken/Mindustry
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.gradle
517 lines (429 loc) · 16.6 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
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
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
buildscript{
ext{
getArcHash = {
return new Properties().with{ p -> p.load(file('gradle.properties').newReader()); return p }["archash"]
}
arcHash = getArcHash()
}
repositories{
mavenLocal()
mavenCentral()
google()
maven{ url "https://oss.sonatype.org/content/repositories/snapshots/" }
maven{ url 'https://jitpack.io' }
//fake repository to download my patched robovm jar from
ivy{
url 'https://github.com/'
patternLayout {
artifact '/[organisation]/[module]/raw/a-single-jar-file/[revision].jar'
}
// This is required in Gradle 6.0+ as metadata file (ivy.xml)
// is mandatory. Docs linked below this code section
metadataSources { artifact() }
}
}
dependencies{
//use local, patched robovm gradle plugin until my PR for gradle 7.0 support is merged
//https://github.com/Anuken/robovm/raw/a-single-jar-file/robovm-gradle-plugin-2.3.14-SNAPSHOT.jar
classpath "Anuken:robovm:robovm-gradle-plugin-2.3.14-SNAPSHOT"
//needed for plugin above
classpath "com.mobidevelop.robovm:robovm-dist-compiler:2.3.13"
classpath "com.github.Anuken.Arc:packer:$arcHash"
classpath "com.github.Anuken.Arc:arc-core:$arcHash"
}
}
plugins{
id 'org.jetbrains.kotlin.jvm' version '1.4.32'
id "org.jetbrains.kotlin.kapt" version "1.4.32"
}
allprojects{
apply plugin: 'maven-publish'
version = 'release'
group = 'com.github.Anuken'
ext{
versionNumber = '7'
if(!project.hasProperty("versionModifier")) versionModifier = 'pre-alpha'
if(!project.hasProperty("versionType")) versionType = 'official'
appName = 'Mindustry'
steamworksVersion = '0b86023401880bb5e586bc404bedbaae9b1f1c94'
rhinoVersion = '9f792d202471fb3789eab7bb261fec13d67287e2'
loadVersionProps = {
return new Properties().with{p -> p.load(file('../core/assets/version.properties').newReader()); return p }
}
debugged = {
return new File(projectDir.parent, '../Mindustry-Debug').exists() && !project.hasProperty("release") && project.hasProperty("args")
}
localArc = {
return !project.hasProperty("release") && new File(projectDir.parent, '../Arc').exists()
}
arcModule = { String name ->
if(localArc()){
return project(":Arc:$name")
}else{
//skip to last submodule
if(name.contains(':')) name = name.split(':').last()
return "com.github.Anuken.Arc:$name:${getArcHash()}"
}
}
generateDeployName = { String platform ->
if(platform == "windows"){
platform += "64"
}
platform = platform.capitalize()
if(platform.endsWith("64") || platform.endsWith("32")){
platform = "${platform.substring(0, platform.length() - 2)}-${platform.substring(platform.length() - 2)}bit"
}
return "[${platform}]${getModifierString()}[${getNeatVersionString()}]${appName}"
}
getVersionString = {
String buildVersion = getBuildVersion()
return "$versionNumber-$versionModifier-$buildVersion"
}
getNeatVersionString = {
String buildVersion = getBuildVersion()
return "v$buildVersion"
}
hasSprites = {
return new File(rootDir, "core/assets/sprites/sprites.aatls").exists()
}
getModifierString = {
if(versionModifier != "release") return "[${versionModifier.toUpperCase()}]"
return ""
}
getBuildVersion = {
if(!project.hasProperty("buildversion")) return "custom build"
return project.getProperties()["buildversion"]
}
getPackage = {
return project.ext.mainClassName.substring(0, project.ext.mainClassName.indexOf("desktop") - 1)
}
findSdkDir = {
//null because IntelliJ doesn't get env variables
def v = System.getenv("ANDROID_HOME")
if(v != null) return v
//rootDir is null here, amazing. brilliant.
def file = new File(rootDir, "local.properties")
def props = new Properties().with{p -> p.load(file.newReader()); return p }
return props.get("sdk.dir")
}
generateLocales = {
def output = 'en\n'
def bundles = new File(project(':core').projectDir, 'assets/bundles/')
bundles.listFiles().each{ other ->
if(other.name == "bundle.properties") return
output += other.name.substring("bundle".length() + 1, other.name.lastIndexOf('.')) + "\n"
}
new File(project(':core').projectDir, 'assets/locales').text = output
new File(project(':core').projectDir, 'assets/basepartnames').text = new File(project(':core').projectDir, 'assets/baseparts/').list().join("\n")
}
writeVersion = {
def pfile = new File(project(':core').projectDir, 'assets/version.properties')
def props = new Properties()
try{
pfile.createNewFile()
}catch(Exception ignored){
}
if(pfile.exists()){
props.load(new FileInputStream(pfile))
String buildid = getBuildVersion()
println("Compiling with build: '$buildid'")
props["type"] = versionType
props["number"] = versionNumber
props["modifier"] = versionModifier
props["build"] = buildid
props.store(pfile.newWriter(), "Autogenerated file. Do not modify.")
}
}
writeProcessors = {
new File(rootDir, "annotations/src/main/resources/META-INF/services/").mkdirs()
def processorFile = new File(rootDir, "annotations/src/main/resources/META-INF/services/javax.annotation.processing.Processor")
def text = new StringBuilder()
def files = new File(rootDir, "annotations/src/main/java")
files.eachFileRecurse(groovy.io.FileType.FILES){ file ->
if(file.name.endsWith(".java") && (file.text.contains(" extends BaseProcessor") || (file.text.contains(" extends AbstractProcessor") && !file.text.contains("abstract class")))){
text.append(file.path.substring(files.path.length() + 1)).append("\n")
}
}
processorFile.text = text.toString().replace(".java", "").replace("/", ".").replace("\\", ".")
}
writePlugins = {
new File(rootDir, "annotations/src/main/resources/META-INF/services/").mkdirs()
def processorFile = new File(rootDir, "annotations/src/main/resources/META-INF/services/com.sun.source.util.Plugin")
def text = new StringBuilder()
def files = new File(rootDir, "annotations/src/main/java")
files.eachFileRecurse(groovy.io.FileType.FILES){ file ->
if(file.name.endsWith(".java") && (file.text.contains(" implements Plugin"))){
text.append(file.path.substring(files.path.length() + 1)).append("\n")
}
}
processorFile.text = text.toString().replace(".java", "").replace("/", ".").replace("\\", ".")
}
}
repositories{
mavenLocal()
mavenCentral()
maven{ url "https://oss.sonatype.org/content/repositories/snapshots/" }
maven{ url "https://oss.sonatype.org/content/repositories/releases/" }
maven{ url 'https://jitpack.io' }
}
task clearCache{
doFirst{
delete{
delete "$rootDir/core/assets/cache"
}
}
}
tasks.withType(JavaCompile){
targetCompatibility = 8
sourceCompatibility = JavaVersion.VERSION_16
options.encoding = "UTF-8"
options.compilerArgs += ["-Xlint:deprecation"]
dependsOn clearCache
options.forkOptions.jvmArgs.addAll([
'--add-opens=jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED',
'--add-opens=jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED'
])
}
}
configure(project(":annotations")){
tasks.withType(JavaCompile){
targetCompatibility = 8
sourceCompatibility = 8
options.fork = true
}
}
//compile with java 8 compatibility for everything except the annotation project
configure(subprojects - project(":annotations")){
tasks.withType(JavaCompile){
options.compilerArgs.addAll(['--release', '8'])
}
tasks.withType(Javadoc){
options{
addStringOption('Xdoclint:none', '-quiet')
addStringOption('-release', '16')
}
}
}
project(":desktop"){
apply plugin: "java"
compileJava.options.fork = true
dependencies{
implementation project(":core")
implementation arcModule("extensions:discord")
implementation arcModule("natives:natives-desktop")
implementation arcModule("natives:natives-freetype-desktop")
if(debugged()) implementation project(":debug")
implementation "com.github.Anuken:steamworks4j:$steamworksVersion"
implementation arcModule("backends:backend-sdl")
}
}
project(":ios"){
apply plugin: "java"
apply plugin: "robovm"
task incrementConfig{
def vfile = file('robovm.properties')
def bversion = getBuildVersion()
def props = new Properties()
if(vfile.exists()){
props.load(new FileInputStream(vfile))
}else{
props['app.id'] = 'io.anuke.mindustry'
props['app.version'] = '6.0'
props['app.mainclass'] = 'mindustry.IOSLauncher'
props['app.executable'] = 'IOSLauncher'
props['app.name'] = 'Mindustry'
}
props['app.build'] = (!props.containsKey("app.build") ? 40 : props['app.build'].toInteger() + 1) + ""
if(bversion != "custom build"){
props['app.version'] = versionNumber + "." + bversion + (bversion.contains(".") ? "" : ".0")
}
props.store(vfile.newWriter(), null)
}
dependencies{
implementation project(":core")
implementation arcModule("natives:natives-ios")
implementation arcModule("natives:natives-freetype-ios")
implementation arcModule("backends:backend-robovm")
compileOnly project(":annotations")
}
}
project(":core"){
apply plugin: "java-library"
apply plugin: "kotlin"
apply plugin: "kotlin-kapt"
kapt{
javacOptions{
option("-source", "16")
option("-target", "1.8")
}
}
compileJava.options.fork = true
task preGen{
outputs.upToDateWhen{ false }
generateLocales()
writeVersion()
writeProcessors()
writePlugins()
}
task copyChangelog{
doLast{
def props = loadVersionProps()
def androidVersion = props['androidBuildCode'].toInteger() - 2
def loglines = file("../changelog").text.split("\n")
def notice = "[This is a truncated changelog, see Github for full notes]"
def maxLength = 460
def androidLogList = [notice] + loglines.findAll{ line -> !line.endsWith("]") || line.endsWith("[Mobile]") || line.endsWith("[Android]")}
def result = ""
androidLogList.forEach{line ->
if(result.length() + line.length() + 1 < maxLength){
result += line + "\n"
}
}
def changelogs = file("../fastlane/metadata/android/en-US/changelogs/")
new File(changelogs, androidVersion + ".txt").text = (result)
}
}
task sourcesJar(type: Jar, dependsOn: classes){
archiveClassifier = 'sources'
from sourceSets.main.allSource
}
task assetsJar(type: Jar, dependsOn: ":tools:pack"){
archiveClassifier = 'assets'
from files("assets"){
exclude "config", "cache", "music", "sounds"
}
}
task musicJar(type: Jar){
archiveClassifier = 'music'
from files("assets"){
include "music/*", "sounds/*"
}
}
artifacts{
archives sourcesJar
archives assetsJar
}
dependencies{
compileJava.dependsOn(preGen)
api "org.lz4:lz4-java:1.7.1"
api arcModule("arc-core")
api arcModule("extensions:flabel")
api arcModule("extensions:freetype")
api arcModule("extensions:g3d")
api arcModule("extensions:fx")
api arcModule("extensions:arcnet")
api "com.github.Anuken:rhino:$rhinoVersion"
if(localArc() && debugged()) api arcModule("extensions:recorder")
if(localArc()) api arcModule(":extensions:packer")
annotationProcessor 'com.github.Anuken:jabel:34e4c172e65b3928cd9eabe1993654ea79c409cd'
compileOnly project(":annotations")
kapt project(":annotations")
}
afterEvaluate{
task mergedJavadoc(type: Javadoc){
def blacklist = [project(":ios"), project(":desktop"), project(":server"), project(":annotations")]
if(findProject(":android") != null){
blacklist += project(":android")
}
source rootProject.subprojects.collect{ project ->
if(!blacklist.contains(project) && project.hasProperty("sourceSets")){
return project.sourceSets.main.allJava
}
}
classpath = files(rootProject.subprojects.collect { project ->
if(!blacklist.contains(project) && project.hasProperty("sourceSets")){
return project.sourceSets.main.compileClasspath
}
})
destinationDir = new File(buildDir, 'javadoc')
}
}
//comp** classes are only used for code generation
jar{
exclude("mindustry/entities/comp/**")
}
}
project(":server"){
apply plugin: "java"
dependencies{
implementation project(":core")
implementation arcModule("backends:backend-headless")
}
}
project(":tests"){
apply plugin: "java"
dependencies{
testImplementation project(":core")
testImplementation "org.junit.jupiter:junit-jupiter-params:5.7.1"
testImplementation "org.junit.jupiter:junit-jupiter-api:5.7.1"
testImplementation arcModule("backends:backend-headless")
testRuntimeOnly "org.junit.jupiter:junit-jupiter-engine:5.7.1"
}
test{
//fork every test so mods don't interact with each other
forkEvery = 1
useJUnitPlatform()
workingDir = new File("../core/assets")
testLogging{
exceptionFormat = 'full'
showStandardStreams = true
}
}
}
project(":tools"){
apply plugin: "java"
dependencies{
implementation project(":core")
implementation arcModule("natives:natives-desktop")
implementation arcModule("natives:natives-freetype-desktop")
implementation arcModule("backends:backend-headless")
}
}
project(":annotations"){
apply plugin: "java-library"
dependencies{
implementation 'com.squareup:javapoet:1.12.1'
implementation "com.github.Anuken.Arc:arc-core:$arcHash"
}
}
configure([":core", ":desktop", ":server", ":tools"].collect{project(it)}){
java{
withJavadocJar()
withSourcesJar()
}
publishing{
publications{
maven(MavenPublication){
from components.java
}
}
}
}
task deployAll{
task cleanDeployOutput{
doFirst{
if(getBuildVersion() == "custom build" || getBuildVersion() == "") throw new IllegalArgumentException("----\n\nSET A BUILD NUMBER FIRST!\n\n----")
if(!project.hasProperty("release")) throw new IllegalArgumentException("----\n\nSET THE RELEASE PROJECT PROPERTY FIRST!\n\n----")
delete{
delete "deploy/"
}
}
}
dependsOn cleanDeployOutput
dependsOn "desktop:packrLinux64"
dependsOn "desktop:packrWindows64"
dependsOn "desktop:packrWindows32"
dependsOn "desktop:packrMacOS"
if(versionModifier != "steam"){
dependsOn "server:deploy"
dependsOn "android:deploy"
}
}
task resolveDependencies{
doLast{
rootProject.allprojects{ project ->
Set<Configuration> configurations = project.buildscript.configurations + project.configurations
configurations.findAll{c -> c.canBeResolved}.forEach{c -> c.resolve()}
}
}
}