-
Notifications
You must be signed in to change notification settings - Fork 669
/
build.gradle
536 lines (475 loc) · 16.7 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
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
/*
* This file is part of Applied Energistics 2.
* Copyright (c) 2013 - 2015, AlgorithmX2, All rights reserved.
*
* Applied Energistics 2 is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Applied Energistics 2 is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
*/
buildscript {
dependencies {
// Fix for the shadow plugin using outdated ASM
classpath 'org.ow2.asm:asm:9.5'
classpath 'org.ow2.asm:asm-commons:9.5'
}
}
plugins {
id "net.neoforged.moddev"
id "maven-publish"
id "com.diffplug.spotless"
id 'io.github.goooler.shadow'
id "de.undercouch.download"
}
apply plugin: ProjectDefaultsPlugin
base {
archivesName = "appliedenergistics2"
}
sourceSets {
main {
java {
srcDir 'src/main/flatbuffers/generated'
}
resources {
srcDir 'src/generated/resources'
}
}
buildtools
}
configurations {
localRuntimeOnly
shaded {
transitive = false
}
buildtoolsImplementation.extendsFrom(compileClasspath)
// Dependencies only used for the guide export, but not shipped
guideExportOnly
configurations.compileClasspath.extendsFrom(guideExportOnly)
configurations.runtimeClasspath.extendsFrom(guideExportOnly)
runtimeClasspath.extendsFrom localRuntimeOnly
}
import appengbuild.*
import com.diffplug.gradle.spotless.JsonExtension
dependencies {
// To be copied into the jar file
shaded project(path: ':libs:markdown', configuration: "archives")
shaded "io.methvin:directory-watcher:${directory_watcher_version}"
shaded "org.yaml:snakeyaml:${snakeyaml_version}"
shaded "com.google.flatbuffers:flatbuffers-java:${flatbuffers_version}"
implementation(project(':libs:markdown')) {
transitive = false
}
// Do not inherit any transitive dependencies here since we rely on those dependencies being
// present in Minecrafts own dependencies already.
implementation("io.methvin:directory-watcher:${directory_watcher_version}") {
transitive = false
}
implementation("org.yaml:snakeyaml:${snakeyaml_version}") {
transitive = false
}
implementation("com.google.flatbuffers:flatbuffers-java:${flatbuffers_version}") {
transitive = false
}
// Used for the guide export
guideExportOnly("org.bytedeco:ffmpeg-platform:${ffmpeg_version}")
// compile against provided APIs
compileOnly "dev.emi:emi-neoforge:${emi_version}:api"
compileOnly "me.shedaniel:RoughlyEnoughItems-neoforge:${project.rei_version}"
compileOnly "mcp.mobius.waila:wthit-api:neo-${project.wthit_version}"
compileOnly "curse.maven:jade-324717:${project.jade_file_id}"
compileOnly "mcjty.theoneprobe:theoneprobe:${project.top_version}"
switch (project.runtime_itemlist_mod) {
case "emi":
localRuntimeOnly "dev.emi:emi-neoforge:${emi_version}"
break
case "rei":
localRuntimeOnly "me.shedaniel:RoughlyEnoughItems-neoforge:${project.rei_version}"
break
}
switch (project.runtime_tooltip_mod) {
case "wthit":
localRuntimeOnly "mcp.mobius.waila:wthit:neo-${project.wthit_version}"
break
case "jade":
localRuntimeOnly "curse.maven:jade-324717:${project.jade_file_id}"
break
case "top":
localRuntimeOnly "mcjty.theoneprobe:theoneprobe:${project.top_version}"
break
}
if (project.runtime_curio == "true") {
localRuntimeOnly("top.theillusivec4.curios:curios-neoforge:${project.curios_version}")
}
// Athena
if (project.runtime_athena == "true") {
localRuntimeOnly("curse.maven:athena-841890:${project.athena_file_id}")
}
// unit test dependencies
testImplementation(platform("org.junit:junit-bom:${project.junit_version}"))
testImplementation(platform("org.assertj:assertj-bom:${project.assertj_version}"))
testImplementation("org.junit.jupiter:junit-jupiter-api")
testImplementation("org.junit.jupiter:junit-jupiter-params")
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine")
testImplementation("org.junit.platform:junit-platform-launcher")
testImplementation("org.assertj:assertj-core")
testImplementation("com.google.guava:guava-testlib:21.0")
testImplementation("org.mockito:mockito-junit-jupiter:5.12.0")
testImplementation("net.neoforged:testframework:${project.neoforge_version}")
compileOnly 'org.apache.commons:commons-configuration2:2.9.0'
buildtoolsImplementation 'de.siegmar:fastcsv:2.1.0'
buildtoolsImplementation 'com.google.code.gson:gson:2.8.9'
}
///////////////////
// Version Number
ext.tag = System.getenv('TAG') ?: ""
if (ext.tag) {
if (!ext.tag.startsWith("neoforge/v")) {
throw new GradleException("Tags for the neoforge version should start with neoforge/: ${ext.tag}")
}
project.version = ext.tag.substring("neoforge/v".length())
} else {
// This essentially tries to implement delay expansion of the project version based on a value source to
// still support configuration caching.
project.version = providers.gradleProperty("version").orElse("").flatMap(version -> {
if (!version.isBlank()) {
return providers.provider { version }
}
return providers.of(ProjectVersionSource.class, spec -> {
spec.getParameters().getDefaultBranches().addAll("main", "neoforge/" + project.minecraft_version)
});
}).get()
}
tasks.register("printProjectVersion", PrintProjectVersion.class);
test {
useJUnitPlatform()
// Might not need this anymore...
systemProperty "guideDev.ae2guide.sources", file("guidebook").absolutePath
}
dependencies {
buildtoolsImplementation 'de.siegmar:fastcsv:2.1.0'
buildtoolsImplementation 'com.google.code.gson:gson:2.8.9'
}
/**
* Configures properties common to all run configurations
*/
Map<String, String> commonSystemProperties = [
'forge.logging.console.level': 'debug',
'appeng.tests' : 'true',
]
neoForge {
version = project.neoforge_version
mods {
ae2 {
sourceSet sourceSets.main
}
}
runs {
configureEach {
gameDirectory = project.file('run')
systemProperties = commonSystemProperties
// property "mixin.debug.export", "true"
additionalRuntimeClasspathConfiguration.extendsFrom configurations.shaded
additionalRuntimeClasspathConfiguration.extendsFrom configurations.guideExportOnly
}
client {
client()
systemProperties = [
* : commonSystemProperties,
"appeng.tests" : "true",
"guideDev.ae2guide.sources": file("guidebook").absolutePath,
]
}
gametestWorld {
client()
programArguments = [
"--username", "AE2Dev", "--quickPlaySingleplayer", "GametestWorld"
]
systemProperties = [
"appeng.tests" : "true",
"guideDev.ae2guide.sources": file("guidebook").absolutePath,
]
}
guide {
client()
systemProperties = [
"guideDev.ae2guide.sources" : file("guidebook").absolutePath,
"guideDev.ae2guide.startupPage": "ae2:index.md"
]
}
server {
server()
}
data {
data()
programArguments = [
'--mod', 'ae2',
'--all',
'--output', file('src/generated/resources/').absolutePath,
'--existing', file('src/main/resources').absolutePath
]
}
guideexport {
client()
systemProperties = [
"appeng.runGuideExportAndExit": "true",
"appeng.guideExportFolder" : file("$buildDir/guide").absolutePath,
"guideDev.ae2guide.sources" : file("guidebook").absolutePath,
"appeng.version" : project.version
]
}
// Use to run the tests
gametest {
type = "gameTestServer"
gameDirectory = project.file("build/gametest")
}
}
unitTest {
enable()
testedMod = mods.ae2
}
}
//////////////
// Artifacts
Map<String, String> expansionVariables = [
"project_version": project.version,
'minecraft_version': project.minecraft_version_range,
'neoforge_version': project.neoforge_version_range,
'top_version': project.top_version_range,
'jade_version': project.jade_version_range
]
processResources {
exclude '.cache'
// Ensure the resources get re-evaluate when the version changes
for (var entry : expansionVariables.entrySet()) {
inputs.property(entry.key, entry.value)
}
filesMatching("META-INF/neoforge.mods.toml") {
expand expansionVariables
filter { line ->
line.replace('version="0.0.0"', "version=\"${expansionVariables['project_version']}\"")
}
}
}
jar {
finalizedBy shadowJar
archiveClassifier = "plain"
}
shadowJar {
from sourceSets.main.output.classesDirs
from sourceSets.main.output.resourcesDir
from('guidebook') {
into 'assets/ae2/ae2guide'
}
relocate "io.methvin", "appeng.shaded.methvin"
relocate "org.yaml.snakeyaml", "appeng.shaded.snakeyaml"
configurations = [project.configurations.shaded]
archiveClassifier = null
}
assemble.dependsOn shadowJar
def publicApiIncludePatterns = {
exclude "**/*Internal.*"
exclude "**/*Internal\$*.*"
include "appeng/api/**"
}
javadoc {
source = sourceSets.main.allJava
classpath = sourceSets.main.compileClasspath + sourceSets.main.output
options.addStringOption('Xdoclint:none', '-quiet')
options.encoding = 'UTF-8'
options.charSet = 'UTF-8'
}
javadoc publicApiIncludePatterns
tasks.register('javadocJar', Jar) {
dependsOn javadoc
archiveClassifier = "javadoc"
from javadoc.destinationDir
}
tasks.register('sourcesJar', Jar) {
archiveClassifier = "sources"
from sourceSets.main.allJava
}
tasks.register('apiJar', Jar) {
archiveClassifier = "api"
// api jar ist just a development aid and serves as both a binary and source jar simultaneously
from sourceSets.main.output
from sourceSets.main.allJava
manifest {
attributes("Fabric-Loom-Remap": true)
}
}
apiJar publicApiIncludePatterns
artifacts {
archives javadocJar
archives sourcesJar
archives apiJar
}
//////////////////
// Maven publish
publishing {
publications {
maven(MavenPublication) {
artifactId = "appliedenergistics2"
version = project.version
artifact shadowJar
artifact sourcesJar
artifact javadocJar
artifact apiJar
}
}
repositories {
maven {
name = "Local"
url = file("build/repo").toURI()
}
}
}
/////////////
// Spotless
spotless {
java {
target 'src/*/java/appeng/**/*.java'
endWithNewline()
indentWithSpaces()
removeUnusedImports()
toggleOffOn()
eclipse().configFile 'codeformat/codeformat.xml'
importOrderFile 'codeformat/ae2.importorder'
// courtesy of diffplug/spotless#240
// https://github.com/diffplug/spotless/issues/240#issuecomment-385206606
custom 'noWildcardImports', {
if (it.contains('*;\n')) {
throw new Error('No wildcard imports allowed')
}
it
}
bumpThisNumberIfACustomStepChanges(1)
}
json {
target 'src/*/resources/**/*.json'
targetExclude 'src/generated/resources/**'
var biomeConfig = it.new JsonExtension.BiomeJson(null)
try {
biomeConfig.downloadDir(new File(rootDir, ".gradle/biome").absolutePath)
} catch (Exception ignored) {
}
addStep(biomeConfig.createStep())
indentWithSpaces(2)
endWithNewline()
}
}
////////////////
// Crowdin
tasks.register('uploadToCrowdin', JavaExec) {
classpath = sourceSets.buildtools.runtimeClasspath
mainClass = 'Crowdin'
args 'upload_source'
workingDir "."
}
tasks.register('uploadTranslations', JavaExec) {
classpath = sourceSets.buildtools.runtimeClasspath
mainClass = 'Crowdin'
args 'upload_translations'
workingDir "."
}
tasks.register('downloadFromCrowdin', JavaExec) {
classpath = sourceSets.buildtools.runtimeClasspath
mainClass = 'Crowdin'
args 'update_translations'
workingDir "."
}
check.dependsOn tasks.register('validateResources', JavaExec) {
group = "verification"
classpath = sourceSets.buildtools.runtimeClasspath
mainClass = 'ValidateResourceIds'
workingDir "."
args "guidebook"
javaLauncher.set(javaToolchains.launcherFor(java.toolchain))
}
/**
* This task download the FlatBuffers compiler suitable for the current platform.
*/
tasks.register('downloadFlatbufferCompiler', Download) {
var os = System.getProperty("os.name").toLowerCase(Locale.ROOT)
var arch = System.getProperty("os.arch")
if (os.startsWith("windows")) {
src "https://github.com/google/flatbuffers/releases/download/v${flatbuffers_version}/Windows.flatc.binary.zip"
} else if (os.startsWith("mac")) {
if (arch == "aarch64") {
src "https://github.com/google/flatbuffers/releases/download/v${flatbuffers_version}/Mac.flatc.binary.zip"
} else if (arch == "amd64") {
src "https://github.com/google/flatbuffers/releases/download/v${flatbuffers_version}/MacIntel.flatc.binary.zip"
} else {
throw new GradleException("Unknown Mac architecture: $arch")
}
} else if (os.startsWith("linux")) {
src "https://github.com/google/flatbuffers/releases/download/v${flatbuffers_version}/Linux.flatc.binary.clang++-12.zip"
} else {
throw new GradleException("Unknown OS: $os")
}
onlyIfModified true
dest layout.buildDirectory.file("flatc.zip")
}
tasks.register('downloadAndUnzipFlatbufferCompiler', Copy) {
dependsOn downloadFlatbufferCompiler
from zipTree(downloadFlatbufferCompiler.dest)
into "${project.buildDir}/flatbuffers-bin"
}
/**
* Update the generated Java Code for our scene export schema.
* The code is checked in so this only needs to be run when the schema changes.
*/
tasks.register('updateFlatbufferSources', Exec) {
group 'build'
dependsOn downloadAndUnzipFlatbufferCompiler
workingDir project.projectDir
commandLine "${project.buildDir}/flatbuffers-bin/flatc",
"--gen-mutable",
"--java-package-prefix", "appeng.flatbuffers",
"--gen-generated",
"--java",
"-o",
"${project.projectDir}/src/main/flatbuffers/generated",
"${project.projectDir}/src/main/flatbuffers/scene.fbs"
doFirst {
file("${project.projectDir}/src/main/flatbuffers/generated").deleteDir()
}
doLast {
}
doLast {
// sadly flatc uses an outdated annotation
def folder = file("${project.projectDir}/src/main/flatbuffers/generated")
folder.eachFileRecurse(groovy.io.FileType.FILES) { file ->
String content = file.text
if (content.contains('@javax.annotation.Generated')) {
content = content.replace('@javax.annotation.Generated', '@javax.annotation.processing.Generated')
file.write(content)
}
}
}
}
/**
* Generate the TypeScript sources for our schema. The sources are manually copied
* over to the website repository.
*/
tasks.register('updateFlatbufferTypescriptSources', Exec) {
group 'build'
dependsOn downloadAndUnzipFlatbufferCompiler
workingDir project.projectDir
commandLine "${project.buildDir}/flatbuffers-bin/flatc",
"--ts-flat-files",
"--ts",
"-o",
"${project.buildDir}/scene-ts",
"${project.projectDir}/src/main/flatbuffers/scene.fbs"
doFirst {
file("${project.buildDir}/scene-ts").deleteDir()
}
}