forked from AppliedEnergistics/Applied-Energistics-2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.gradle
661 lines (582 loc) · 20.8 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
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
/*
* 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 {
classpath 'org.spongepowered:mixingradle:0.7-SNAPSHOT'
}
}
plugins {
id "net.neoforged.gradle"
id "maven-publish"
id "com.diffplug.spotless"
id "com.github.johnrengelman.shadow"
id "de.undercouch.download"
id "eclipse"
}
sourceSets {
main {
java {
srcDir 'src/main/flatbuffers/generated'
}
resources {
srcDir 'src/generated/resources'
}
}
test {
}
buildtools
}
apply plugin: 'org.spongepowered.mixin'
configurations {
shaded {
transitive = false
}
buildtoolsImplementation.extendsFrom(compileClasspath)
internal {
visible = false
canBeConsumed = false
canBeResolved = false
}
configurations.compileClasspath.extendsFrom(internal)
configurations.runtimeClasspath.extendsFrom(internal)
configurations.testCompileClasspath.extendsFrom(internal)
configurations.testRuntimeClasspath.extendsFrom(internal)
}
// All jar files from this folder will be added automatically as runtime mod dependencies
def extraModsDir = "extra-mods-${minecraft_version}"
file(extraModsDir).mkdir()
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}"
minecraftLibrary(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.
minecraftLibrary("io.methvin:directory-watcher:${directory_watcher_version}") {
transitive = false
}
minecraftLibrary("org.yaml:snakeyaml:${snakeyaml_version}") {
transitive = false
}
minecraftLibrary("com.google.flatbuffers:flatbuffers-java:${flatbuffers_version}") {
transitive = false
}
// Used for the guide export
minecraftLibrary("org.bytedeco:ffmpeg-platform:6.0-1.5.9")
minecraft "net.neoforged:forge:${minecraft_version}-${neoforge_version}"
// compile against provided APIs
compileOnly fg.deobf("mezz.jei:jei-${jei_minecraft_version}-common-api:${jei_version}")
compileOnly fg.deobf("mezz.jei:jei-${jei_minecraft_version}-forge-api:${jei_version}")
// Always depend on the REI API to compile
if (project.runtime_itemlist_mod == "jei") {
runtimeOnly fg.deobf("mezz.jei:jei-${jei_minecraft_version}-forge:${jei_version}")
compileOnly "me.shedaniel.cloth:basic-math:0.6.1"
compileOnly fg.deobf("dev.architectury:architectury-forge:${project.architectury_version}")
compileOnly fg.deobf("me.shedaniel:RoughlyEnoughItems-forge:${project.rei_version}")
} else if (project.runtime_itemlist_mod == "rei") {
implementation "me.shedaniel.cloth:basic-math:0.6.1"
implementation fg.deobf("me.shedaniel.cloth:cloth-config-forge:${project.cloth_config_version}")
implementation fg.deobf("dev.architectury:architectury-forge:${project.architectury_version}")
implementation fg.deobf("me.shedaniel:RoughlyEnoughItems-forge:${project.rei_version}")
} else {
compileOnly fg.deobf("me.shedaniel.cloth:cloth-config-forge:${project.cloth_config_version}")
compileOnly fg.deobf("dev.architectury:architectury-forge:${project.architectury_version}")
compileOnly fg.deobf("me.shedaniel:RoughlyEnoughItems-forge:${project.rei_version}")
}
// Locally sourced extra mods for runtime (i.e. testing)
for (extraModJar in fileTree(dir: extraModsDir, include: '*.jar')) {
def basename = extraModJar.name.substring(0, extraModJar.name.length() - ".jar".length())
def versionSep = basename.lastIndexOf('-')
assert versionSep != -1
def artifactId = basename.substring(0, versionSep)
def version = basename.substring(versionSep + 1)
runtimeOnly fg.deobf("extra-mods:$artifactId:$version")
}
if (project.runtime_tooltip_mod == "wthit") {
runtimeOnly fg.deobf("mcp.mobius.waila:wthit:forge-${project.wthit_version}")
runtimeOnly fg.deobf("lol.bai:badpackets:forge-0.1.2")
} else {
compileOnly fg.deobf("mcp.mobius.waila:wthit-api:forge-${project.wthit_version}")
}
if (project.runtime_tooltip_mod == "jade") {
implementation fg.deobf("curse.maven:jade-324717:${project.jade_file_id}")
} else {
compileOnly fg.deobf("curse.maven:jade-324717:${project.jade_file_id}")
}
def topDependency = "curse.maven:the-one-probe-245211:4159743"
if (project.runtime_tooltip_mod == "top") {
implementation fg.deobf(topDependency)
} else {
compileOnly topDependency
}
// unit test dependencies
testImplementation(platform("org.junit:junit-bom:${project.junit_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:3.19.0")
testImplementation("com.google.guava:guava-testlib:21.0")
testImplementation("org.mockito:mockito-junit-jupiter:5.3.1")
compileOnly 'org.apache.commons:commons-configuration2:2.9.0'
// Annotation Processors
annotationProcessor 'org.spongepowered:mixin:0.8.4:processor'
}
archivesBaseName = artifact_basename
allprojects {
group = artifact_group
java {
toolchain {
languageVersion = JavaLanguageVersion.of(17)
}
}
repositories {
mavenLocal()
mavenCentral()
maven {
url "https://maven.shedaniel.me/"
content {
includeGroup "me.shedaniel"
includeGroup "me.shedaniel.cloth"
includeGroup "dev.architectury"
}
}
maven {
url "https://maven2.bai.lol"
content {
includeGroup "mcp.mobius.waila"
includeGroup "lol.bai"
}
}
maven {
url "https://maven.parchmentmc.net/"
content {
includeGroup "org.parchmentmc.data"
}
}
// For the "No Indium?" mod
maven {
url = 'https://maven.cafeteria.dev/releases/'
content {
includeGroup "me.luligabi"
}
}
maven {
name 'modmaven'
url "https://modmaven.dev/"
content {
includeGroup "mezz.jei"
}
}
maven {
name 'cursemaven'
url "https://www.cursemaven.com"
content {
includeGroup "curse.maven"
}
}
maven {
url "https://maven.blamejared.com"
content {
includeGroup "vazkii.patchouli"
}
}
flatDir {
name "extra-mods"
dir file(extraModsDir)
}
maven { // for TOP
url "https://maven.k-4u.nl/"
content {
includeGroup "mcjty"
}
}
maven { url = 'https://repo.spongepowered.org/maven' }
}
// ensure everything uses UTF-8 and not some random codepage chosen by gradle
compileJava.options.encoding = 'UTF-8'
tasks.withType(JavaCompile) {
options.encoding = 'UTF-8'
options.deprecation = false
options.compilerArgs << "-Xmaxerrs" << "9999"
}
}
///////////////////
// Version Number
ext.pr = System.getenv('PR_NUMBER') ?: ""
if (ext.pr) {
version = version + "+pr." + ext.pr
}
ext.branch = System.getenv('BRANCH') ?: ""
if (ext.branch) {
version = version + "+branch." + ext.branch
}
ext.tag = System.getenv('TAG') ?: ""
if (ext.tag) {
if (!ext.tag.startsWith("forge/v")) {
throw new GradleException("Tags for the forge version should start with forge/: ${ext.tag}")
}
version = ext.tag.substring("forge/v".length())
// Validate that the rest is a semver version
if (version ==~ /^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$/) {
if (System.getenv("GITHUB_ENV")) {
def envFile = new File(System.getenv("GITHUB_ENV"))
envFile.append("VERSION=${version}")
}
} else {
throw new GradleException("Invalid semver: $version")
}
}
ext.isAlpha = project.version.contains("alpha")
ext.isBeta = project.version.contains("beta")
test {
useJUnitPlatform()
}
dependencies {
buildtoolsImplementation 'de.siegmar:fastcsv:2.1.0'
buildtoolsImplementation 'com.google.code.gson:gson:2.8.9'
}
/**
* Configures properties common to all run configurations
*/
def commonRunProperties = {
workingDirectory project.file('run')
property 'forge.logging.console.level', 'debug'
property 'fml.earlyprogresswindow', 'false'
property 'appeng.tests', 'true'
property 'appeng.version', project.version
jvmArgs "--add-opens", "java.base/sun.security.util=ALL-UNNAMED"
jvmArgs "--add-opens", "java.base/java.util.jar=ALL-UNNAMED"
// See https://github.com/Vazkii/Patchouli#mixin-troubleshooting
property 'mixin.env.remapRefMap', 'true'
property 'mixin.env.refMapRemappingFile', "${projectDir}/build/createSrgToMcp/output.srg"
// property "mixin.debug.export", "true"
mods {
appliedenergistics2 {
source sourceSets.main
}
}
}
////////////////////
// Forge/Minecraft
minecraft {
mappings channel: 'official', version: project.minecraft_version
accessTransformer = file('src/main/resources/META-INF/accesstransformer.cfg')
runs {
client {
with commonRunProperties
property "appeng.tests", "true"
property "guideDev.ae2guide.sources", file("guidebook").absolutePath
}
gametestWorld {
parent runs.client
args "--username", "AE2Dev", "--quickPlaySingleplayer", "GametestWorld"
property "appeng.tests", "true"
property "guideDev.ae2guide.sources", file("guidebook").absolutePath
}
guide {
parent runs.client
with commonRunProperties
property "guideDev.ae2guide.sources", file("guidebook").absolutePath
property "guideDev.ae2guide.startupPage", "ae2:index.md"
}
server {
with commonRunProperties
}
data {
with commonRunProperties
args '--mod', 'ae2', '--all', '--output', file('src/generated/resources/'), "--existing", file("src/main/resources")
}
guideexport {
parent runs.client
with commonRunProperties
property "appeng.runGuideExportAndExit", "true"
property "appeng.guideExportFolder", file("$buildDir/guide").absolutePath
property "guideDev.ae2guide.sources", file("guidebook").absolutePath
}
// Use to run the tests
gametest {
parent server
with commonRunProperties
workingDirectory "build/gametest"
}
}
}
///////////
// Mixins
mixin {
add sourceSets.main, "ae2.mixins.refmap.json"
}
//////////////
// Artifacts
processResources {
inputs.property("version", version)
exclude '.cache'
filesMatching("META-INF/mods.toml") {
expand 'minecraft_version': project.minecraft_version_range, 'neoforge_version': project.neoforge_version_range,
'jei_version': project.jei_version_range, 'top_version': project.top_version_range,
'jade_version': project.jade_version_range
filter { line ->
line.replace('version="0.0.0"', "version=\"$version\"")
}
}
}
jar.enabled = false // Replaced by "shadowJar"
shadowJar {
finalizedBy 'reobfShadowJar'
from sourceSets.main.output.classesDirs
from sourceSets.main.output.resourcesDir
from('guidebook') {
into 'assets/ae2/ae2guide'
}
manifest {
attributes([
"Specification-Title" : "Applied Energistics 2",
"Specification-Vendor" : "TeamAppliedEnergistics",
"Specification-Version" : "${project.version}",
"Implementation-Title" : "${project.name}",
"Implementation-Version": "${project.version}",
"Implementation-Vendor" : "TeamAppliedEnergistics",
"MixinConfigs" : "ae2.mixins.json"
])
}
relocate "io.methvin", "appeng.shaded.methvin"
relocate "org.yaml.snakeyaml", "appeng.shaded.snakeyaml"
relocate "com.google.flatbuffers", "appeng.shaded.flatbuffers"
configurations = [project.configurations.shaded]
archiveClassifier = null
}
reobf {
shadowJar {}
}
afterEvaluate {
tasks.reobfJar.enabled = false
}
tasks.assemble.dependsOn reobfShadowJar
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
task javadocJar(type: Jar, dependsOn: javadoc, group: "build") {
archiveClassifier = "javadoc"
from javadoc.destinationDir
}
task sourcesJar(type: Jar) {
archiveClassifier = "sources"
from sourceSets.main.allJava
}
task apiJar(type: Jar, group: "build") {
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) {
groupId = project.group
artifactId = project.archivesBaseName
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')
}
}
bumpThisNumberIfACustomStepChanges(1)
}
format 'json', {
target 'src/*/resources/**/*.json'
targetExclude 'src/generated/resources/**'
prettier().config(['parser': 'json'])
}
}
////////////////
// Crowdin
task uploadToCrowdin(type: JavaExec) {
classpath = sourceSets.buildtools.runtimeClasspath
mainClass = 'Crowdin'
args 'upload_source'
workingDir "."
}
task uploadTranslations(type: JavaExec) {
classpath = sourceSets.buildtools.runtimeClasspath
mainClass = 'Crowdin'
args 'upload_translations'
workingDir "."
}
task downloadFromCrowdin(type: JavaExec) {
classpath = sourceSets.buildtools.runtimeClasspath
mainClass = 'Crowdin'
args 'update_translations'
workingDir "."
}
////////////////
// IntelliJ Project Import
// The Mixin annotation process does not have an obfuscation source when running through the IntelliJ compiler,
// thus we have to prevent it from being activated as part of importing this Gradle project into IntelliJ.
if (System.getProperty("idea.sync.active") == "true") {
afterEvaluate {
tasks.withType(JavaCompile).all {
it.options.annotationProcessorPath = files()
}
}
}
// See https://github.com/AppliedEnergistics/Applied-Energistics-2/issues/5259
// Gradle module metadata contains mapped dependencies, making our artifacts unconsumable
tasks.withType(GenerateModuleMetadata) {
enabled = false
}
check.dependsOn tasks.register('validateResources', JavaExec) {
group = "verification"
classpath = sourceSets.buildtools.runtimeClasspath
mainClass = 'ValidateResourceIds'
workingDir "."
args "guidebook"
}
/**
* 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 "${project.buildDir}/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()
}
}
afterEvaluate {
}