-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathbuild.gradle
544 lines (472 loc) · 22.1 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
import com.github.jengelman.gradle.plugins.shadow.transformers.Transformer
import com.github.jengelman.gradle.plugins.shadow.transformers.TransformerContext
import org.apache.tools.zip.ZipEntry
import org.apache.tools.zip.ZipOutputStream
import org.codehaus.plexus.util.IOUtil
buildscript {
repositories {
maven {
name = 'Forge'
url = 'https://maven.minecraftforge.net/'
}
maven {
name = 'Sponge Mixin'
url = 'https://repo.spongepowered.org/maven'
}
mavenCentral()
gradlePluginPortal()
}
dependencies {
classpath ('net.minecraftforge.gradle:ForgeGradle:6.0.+') { changing = true }
classpath 'com.github.johnrengelman:shadow:8.1.1'
classpath 'org.spongepowered:mixingradle:0.7-SNAPSHOT'
}
}
plugins {
id 'fabric-loom' version "${fabricLoomVersion}" apply false
}
enum SubprojectType {
CORE(false), FORGE(true), FABRIC(true), LIBRARY(false)
public final boolean isMod
private SubprojectType(boolean isMod) {
this.isMod = isMod
}
}
subprojects { p ->
def subprojectType = {
if (project.name == 'core') SubprojectType.CORE
else if (project.name.startsWith('forge')) SubprojectType.FORGE
else if (project.name.startsWith('fabric')) SubprojectType.FABRIC
else SubprojectType.LIBRARY
}()
// Match version
def mcVersionMatcher = project.name =~ /^[a-zA-Z]+(\d+)\.(.+)$/
def mcVersion = mcVersionMatcher.find() ? Double.parseDouble(mcVersionMatcher.group(2)) : null
apply plugin: 'java'
if (subprojectType == SubprojectType.CORE || subprojectType == SubprojectType.LIBRARY) {
apply plugin: 'maven-publish'
}
else if (subprojectType == SubprojectType.FORGE) {
apply plugin: 'net.minecraftforge.gradle'
apply plugin: 'org.spongepowered.mixin'
apply plugin: 'com.github.johnrengelman.shadow'
}
else if (subprojectType == SubprojectType.FABRIC) {
apply plugin: 'fabric-loom'
}
def (javaVersionInteger, javaVersionEnum) = {
if (mcVersion >= 20.5) [ 21, JavaVersion.VERSION_21 ]
else if (mcVersion >= 18 ) [ 17, JavaVersion.VERSION_17 ]
else [ 8, JavaVersion.VERSION_1_8 ] // this includes CORE and LIBRARY
}()
println("Java version set to $javaVersionEnum for $p")
if (javaVersionInteger != 8) {
// Java 8 does not support the command line argument '--release'
// so this configuration should not be applied to that version
tasks.withType(JavaCompile).configureEach {
it.options.release.set javaVersionInteger
}
}
java {
if (subprojectType == SubprojectType.FABRIC) withSourcesJar()
toolchain.languageVersion.set(JavaLanguageVersion.of(javaVersionInteger))
sourceCompatibility = targetCompatibility = javaVersionEnum
}
if (subprojectType == SubprojectType.FABRIC) {
loom {
splitEnvironmentSourceSets()
mods {
bteterrarenderer {
sourceSet sourceSets.main
sourceSet sourceSets.client
}
}
def accessWidener = file("src/main/resources/${project.mod_id}.accesswidener")
if (accessWidener.exists()) accessWidenerPath = accessWidener
}
jar {}
}
configurations {
shadowDep
compileAndTestOnly
implementation.extendsFrom shadowDep
compileOnly.extendsFrom compileAndTestOnly
testImplementation.extendsFrom compileAndTestOnly
if (subprojectType == SubprojectType.FABRIC) include.extendsFrom shadowDep
}
dependencies {
if (project.name != 'common') shadowDep project(':common')
if (project.name != 'common' && project.name != 'mcconnector') {
shadowDep project(':mcconnector')
}
if (project.name == 'ogc3dtiles') {
shadowDep project(':draco')
}
if (subprojectType != SubprojectType.LIBRARY) {
shadowDep project(':draco')
shadowDep project(':terraplusplus')
shadowDep project(':mcconnector')
shadowDep project(':ogc3dtiles')
}
if (subprojectType.isMod) {
shadowDep project(':core')
}
if (subprojectType == SubprojectType.FABRIC) {
minecraft "com.mojang:minecraft:${project.minecraftVersion}"
mappings "net.fabricmc:yarn:${project.yarnMappings}:v2"
modImplementation "net.fabricmc:fabric-loader:${rootProject.fabricLoaderVersion}"
modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabricVersion}"
}
else if (subprojectType == SubprojectType.FORGE) {
minecraft "net.minecraftforge:forge:${project.minecraftVersion}-${project.forgeVersion}"
}
// We should use shadowDep(group: ..., name: ..., version: ...) instead of shadowDep('group:name:version')
// since fabric's "include" configuration doesn't allow us to do the latter
// ps: fabric ruined it all
shadowDep(group: 'com.fasterxml.jackson.core', name: 'jackson-annotations', version: '2.14.2')
shadowDep(group: 'com.fasterxml.jackson.core', name: 'jackson-core' , version: '2.14.2')
shadowDep(group: 'com.fasterxml.jackson.core', name: 'jackson-databind' , version: '2.14.2')
shadowDep(group: 'com.fasterxml.jackson.dataformat', name: 'jackson-dataformat-yaml', version: '2.14.2')
shadowDep(group: 'de.javagl', name: 'jgltf-impl-v2', version: '2.0.3')
shadowDep(group: 'de.javagl', name: 'jgltf-model' , version: '2.0.3')
shadowDep(group: 'net.daporkchop.lib', name: 'common', version: '0.5.7-SNAPSHOT') { exclude group: 'io.netty' }
shadowDep(group: 'net.daporkchop.lib', name: 'binary', version: '0.5.7-SNAPSHOT') { exclude group: 'io.netty' }
shadowDep(group: 'net.daporkchop.lib', name: 'unsafe', version: '0.5.7-SNAPSHOT')
shadowDep(group: 'org.apache.xmlgraphics', name: 'batik-anim' , version: '1.17')
shadowDep(group: 'org.apache.xmlgraphics', name: 'batik-awt-util' , version: '1.17')
shadowDep(group: 'org.apache.xmlgraphics', name: 'batik-bridge' , version: '1.17')
shadowDep(group: 'org.apache.xmlgraphics', name: 'batik-codec' , version: '1.17')
shadowDep(group: 'org.apache.xmlgraphics', name: 'batik-constants' , version: '1.17')
shadowDep(group: 'org.apache.xmlgraphics', name: 'batik-css' , version: '1.17')
shadowDep(group: 'org.apache.xmlgraphics', name: 'batik-dom' , version: '1.17')
shadowDep(group: 'org.apache.xmlgraphics', name: 'batik-ext' , version: '1.17')
shadowDep(group: 'org.apache.xmlgraphics', name: 'batik-gvt' , version: '1.17')
shadowDep(group: 'org.apache.xmlgraphics', name: 'batik-i18n' , version: '1.17')
shadowDep(group: 'org.apache.xmlgraphics', name: 'batik-parser' , version: '1.17')
shadowDep(group: 'org.apache.xmlgraphics', name: 'batik-script' , version: '1.17')
shadowDep(group: 'org.apache.xmlgraphics', name: 'batik-svg-dom' , version: '1.17')
shadowDep(group: 'org.apache.xmlgraphics', name: 'batik-transcoder', version: '1.17')
shadowDep(group: 'org.apache.xmlgraphics', name: 'batik-util' , version: '1.17')
shadowDep(group: 'org.apache.xmlgraphics', name: 'batik-xml' , version: '1.17')
shadowDep(group: 'org.osgeo', name: 'proj4j', version: '0.1.0')
shadowDep(group: 'org.w3c.dom', name: 'svg' , version: '1.1.0')
shadowDep(group: 'org.w3c.dom', name: 'smil', version: '1.0.0')
shadowDep(group: 'org.yaml', name: 'snakeyaml', version: '1.33')
if (mcVersion > 12) { // for T++
shadowDep(group: 'lzma', name: 'lzma', version: '0.0.1')
}
if (mcVersion < 19) {
shadowDep(group: 'org.joml', name: 'joml', version: '1.10.8') {
exclude group: 'org.jetbrains', module: 'annotations'
}
}
if (mcVersion >= 19) {
shadowDep(group: 'io.netty', name: 'netty-codec-http' , version: '4.1.9.Final')
shadowDep(group: 'io.netty', name: 'netty-codec-http2', version: '4.1.9.Final')
shadowDep(group: 'org.apache.xmlgraphics', name: 'xmlgraphics-commons', version: '2.9')
shadowDep(group: 'org.w3c.css', name: 'sac', version: '1.3')
}
compileAndTestOnly 'org.apache.logging.log4j:log4j-core:2.20.0' // Minecraft
compileAndTestOnly 'org.apache.commons:commons-lang3:3.12.0' // Minecraft
compileAndTestOnly 'commons-codec:commons-codec:1.16.0' // Minecraft; for T++
compileAndTestOnly 'com.google.guava:guava:31.1-jre' // Minecraft; for T++
compileAndTestOnly 'io.netty:netty-all:4.1.9.Final' // Minecraft; for T++
compileAndTestOnly 'lzma:lzma:0.0.1' // Minecraft
if (!subprojectType.isMod) {
compileAndTestOnly 'org.joml:joml:1.10.8' // Minecraft (>=1.18)
}
compileOnly 'org.projectlombok:lombok:1.18.32'
testCompileOnly 'org.projectlombok:lombok:1.18.32'
annotationProcessor 'org.projectlombok:lombok:1.18.32'
if (subprojectType == SubprojectType.FORGE) {
annotationProcessor 'org.spongepowered:mixin:0.8.5:processor'
testImplementation 'org.spongepowered:lwts:1.0.0'
testImplementation 'org.spongepowered:mixin:0.8.5'
testAnnotationProcessor 'org.spongepowered:mixin:0.8.5:processor'
}
testImplementation 'junit:junit:4.13.2'
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.8.2'
testImplementation 'org.apache.logging.log4j:log4j-core:2.20.0'
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.8.2'
testRuntimeOnly 'junit:junit:4.13.2'
}
// Since we're going to do jar-in-jar for fabric,
// we don't also need to "relocate" dependencies on there.
// only forge needs the relocations
if (subprojectType == SubprojectType.FORGE) {
minecraft {
mappings channel: "${project.mappingsChannel}", version: "${project.mappingsVersion}"
def accessTransformerPath = file("src/main/resources/META-INF/accesstransformer.cfg")
if (accessTransformerPath.exists()) accessTransformer = accessTransformerPath
runs {
client {
workingDirectory project.file('run')
property 'forge.logging.markers', 'REGISTRIES'
property 'forge.logging.console.level', 'debug'
mods {
bteterrarenderer { source sourceSets.main }
}
}
server {
workingDirectory project.file('run')
property 'forge.logging.markers', 'REGISTRIES'
property 'forge.logging.console.level', 'debug'
mods {
bteterrarenderer { source sourceSets.main }
}
}
gameTestServer {
workingDirectory project.file('run')
property 'forge.logging.markers', 'REGISTRIES'
property 'forge.logging.console.level', 'debug'
mods {
bteterrarenderer { source sourceSets.main }
}
}
data {
workingDirectory project.file('run')
property 'forge.logging.markers', 'REGISTRIES'
property 'forge.logging.console.level', 'debug'
args '--mod', 'bteterrarenderer', '--all', '--output', file('src/generated/resources/'), '--existing', file('src/main/resources/')
mods {
bteterrarenderer { source sourceSets.main }
}
}
}
}
shadowJar {
configurations = [ project.configurations.shadowDep ]
def dependenciesLocation = "${project.mod_group}.${project.mod_id}.dep"
def dependencyReplacements = [
'com.fasterxml.jackson': 'jackson',
'de.javagl.jgltf': 'jgltf',
'net.daporkchop.lib': 'porklib',
'org.apache.commons.io': 'apache.commons.io',
'org.apache.commons.logging': 'apache.commons.logging',
'org.apache.xmlgraphics': 'xmlgraphics',
'org.apache.batik': 'batik',
'org.apache.xmlcommons': 'xmlcommons',
'org.joml': 'joml',
'org.osgeo.proj4j': 'proj4j',
'org.w3c.css.sac': 'w3ccss.sac',
'org.w3c.dom.smil': 'w3cdom.smil',
'org.w3c.dom.svg': 'w3cdom.svg',
'org.yaml.snakeyaml': 'snakeyaml'
].collectEntries { k, v -> [ k, "$dependenciesLocation.$v" ] } as Map<String, String>
dependencyReplacements.each { relocate it.key, it.value }
transform(ReplacePropertyContentTransformer) {
replacements = dependencyReplacements
}
archiveClassifier.set(null)
exclude '**/module-info.class' // Java 8 bug: Minecraft will ignore the mod file if 'module-info.class' is included
exclude 'license/**/*' // Comes with Batik SVG
exclude 'about_files/**/*' // Comes with W3C SVG
exclude 'about.html' // Comes with W3C SVG
exclude 'plugin.properties' // Comes with W3C SVG
exclude 'kotlin/**/*' // Comes with JOML
exclude 'javax/xml/**/*'
exclude 'org/w3c/dom/bootstrap/**/*'
exclude 'org/w3c/dom/css/**/*'
exclude 'org/w3c/dom/events/**/*'
exclude 'org/w3c/dom/html/**/*'
exclude 'org/w3c/dom/ls/**/*'
exclude 'org/w3c/dom/ranges/**/*'
exclude 'org/w3c/dom/stylesheets/**/*'
exclude 'org/w3c/dom/traversal/**/*'
exclude 'org/w3c/dom/views/**/*'
exclude 'org/w3c/dom/xpath/**/*'
exclude 'org/w3c/dom/*'
exclude 'org/xml/sax/**/*'
}
reobf {
shadowJar {}
}
tasks.named('shadowJar').configure { dependsOn('reobfJar') }
tasks.named('build').configure { dependsOn('shadowJar') }
sourceSets.main.resources { srcDir 'src/generated/resources' }
mixin {
//noinspection GroovyAssignabilityCheck
add sourceSets.main, 'mixins.bteterrarenderer.refmap.json'
config 'mixins.bteterrarenderer.json'
}
jar {
manifest.attributes(
"MixinConfigs": 'mixins.bteterrarenderer.json',
"FMLAT": 'accesstransformer.cfg',
"ForceLoadAsMod": 'true',
"TweakClass": 'org.spongepowered.asm.launch.MixinTweaker',
"TweakOrder": 0,
"Manifest-Version": 1.0
)
}
}
processResources {
duplicatesStrategy = DuplicatesStrategy.INCLUDE
def target = layout.buildDirectory.dir('resources/main').get().asFile
// Replace templates
def resourceTargets = [
'mcmod.info', // Forge <= 1.12.2
'META-INF/mods.toml', // Forge >= 1.13
'fabric.mod.json' // Fabric
]
def replaceProperties = [
// Version properties
version: rootProject.mod_version,
mcversion: project.minecraftVersion,
// Mod config file properties
authors: rootProject.mod_authors,
displayName: rootProject.mod_displayName,
description: rootProject.mod_description,
url: rootProject.mod_url,
sourceUrl: rootProject.mod_sourceUrl,
discordUrl: rootProject.mod_discordUrl,
credits: rootProject.mod_credits,
license: rootProject.mod_license,
fabricLoaderVersion: rootProject.fabricLoaderVersion
]
// this will ensure that this task is redone when the versions change.
inputs.properties replaceProperties
filesMatching(resourceTargets) {
expand replaceProperties
}
copy {
from(sourceSets.main.resources) {
include resourceTargets
expand replaceProperties
}
into target
}
// Make .json from .lang
doLast {
if (subprojectType == SubprojectType.CORE) {
fileTree(dir: outputs.files.asPath, include: '**/*.lang').each { File langFile ->
// Make json content
String content = langFile.getText('UTF-8').split('\n')
.collect { it.replaceFirst(/#.*/, '') }
.collect { it =~ /([^=]+)=(.+)/ }
.findAll { it.find() }
.collect { [ it.group(1), it.group(2) ] }
.collect { " \"${it[0]}\": \"${it[1].replaceAll('"', '\\"')}\"" }
.join(",\n")
// Write to json
File jsonFile = file(langFile.path.replaceFirst(~/\.[^.]+$/, '') + '.json')
jsonFile.setText("{\n$content\n}", 'UTF-8')
}
}
else if (subprojectType.isMod) {
File logoFile = new File(project(':core').projectDir, 'src/main/resources/icon.png')
byte[] logoContent = logoFile.readBytes()
File targetLogoFile = new File(outputs.files.asPath, 'icon.png')
targetLogoFile.setBytes(logoContent)
}
}
}
if (subprojectType.isMod) {
project.tasks.register('copyBuildResultToRoot', Copy) {
group = 'build'
description = 'Copies build result into root build directory'
from "${project.projectDir}/build/libs"
into "${rootProject.projectDir}/build/libs"
dependsOn('build')
}
tasks.named('build').configure {
finalizedBy('copyBuildResultToRoot')
}
project.tasks.register('cleanModProjects', Delete) {
group = 'build'
description = 'Cleans mod projects'
dependsOn('clean')
}
}
else {
tasks.named('test').configure {
dependsOn(rootProject.tasks.gitSubmoduleUpdate)
}
project.tasks.register('buildNonModProjects') {
group = 'build'
description = 'Builds non-mod projects.\n' +
'This is because fabric requires dependency jars to be present before building.'
dependsOn('build')
}
}
}
allprojects { p ->
apply plugin: 'java'
apply plugin: 'maven-publish'
version = "${rootProject.mod_version}-${project.name}" // ex: 1.03-forge1.12.2
group = rootProject.mod_group
archivesBaseName = rootProject.mod_id
compileJava.options.encoding = 'UTF-8'
repositories {
mavenCentral()
maven { url "https://www.jabylon.org/maven/" } // W3C SVG
maven { url "https://repo.spongepowered.org/maven/" } // lzma
maven { url "https://maven.daporkchop.net/" } // leveldb
maven { url "https://repo.opencollab.dev/snapshot/" } // leveldb
maven { url "https://jitpack.io/" } // cubicchunks, cubicworldgen, terraplusplus
maven { url "https://repo.elytradev.com/" } // jankson
}
}
publishing {
publications {
//noinspection GroovyAssignabilityCheck
maven(MavenPublication) {
//noinspection GroovyAssignabilityCheck
groupId = 'com.mndk'
//noinspection GroovyAssignabilityCheck
artifactId = 'bteterrarenderer-core'
version = rootProject.mod_version
//noinspection GroovyAssignabilityCheck
from project(':core').components.java
}
}
}
tasks.register('gitSubmoduleUpdate', Exec) {
group = 'other'
description = 'Updates submodules'
commandLine 'git', 'submodule', 'update', '--init'
def stdout = new ByteArrayOutputStream()
standardOutput = stdout
doLast {
println('Submodule update command output: ')
if (stdout.size() > 0) {
println(stdout.toString())
} else {
println('(none)')
}
}
}
class ReplacePropertyContentTransformer implements Transformer {
@Input
Map<String, String> replacements
private final Map<String, String> pathMap = new HashMap<>()
boolean canTransformResource(FileTreeElement fileTreeElement) {
return fileTreeElement.relativePath.pathString.endsWith('.properties')
}
void transform(TransformerContext context) {
// Copy contents
var buffer = new ByteArrayOutputStream()
IOUtil.copy(context.is, buffer)
context.is.close()
var content = buffer.toString('UTF-8')
// Replace if exists
this.replacements.each { k, v ->
if (!content.contains(k)) return
content = content.replaceAll(k, v)
}
this.pathMap[context.path] = content
}
boolean hasTransformedResource() { !this.pathMap.isEmpty() }
void modifyOutputStream(ZipOutputStream os, boolean b) {
def zipWriter = new OutputStreamWriter(os, 'UTF-8')
this.pathMap.each { path, content ->
var entry = new ZipEntry(path)
entry.time = TransformerContext.getEntryTimestamp(b, entry.time)
os.putNextEntry(entry)
IOUtil.copy(new ByteArrayInputStream(content.getBytes('UTF-8')), zipWriter)
zipWriter.flush()
os.closeEntry()
}
this.pathMap.clear()
}
}