forked from BluSunrize/ImmersiveEngineering
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.gradle
600 lines (538 loc) · 20.5 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
import groovy.json.JsonOutput
import groovy.json.JsonSlurper
import net.minecraftforge.gradle.common.tasks.SignJar
import org.gradle.work.Incremental
buildscript {
repositories {
maven { url 'https://maven.minecraftforge.net' }
maven {url 'https://plugins.gradle.org/m2/'}
mavenCentral()
maven {url 'https://repo.spongepowered.org/repository/maven-public/'}
maven { url 'https://maven.parchmentmc.org' }
}
dependencies {
classpath group: 'net.minecraftforge.gradle', name: 'ForgeGradle', version: '5.1.+', changing: true
classpath 'gradle.plugin.com.github.jengelman.gradle.plugins:shadow:7.0.0'
classpath 'org.spongepowered:mixingradle:0.7-SNAPSHOT'
classpath 'org.parchmentmc:librarian:1.+'
classpath "org.jetbrains.gradle.plugin.idea-ext:org.jetbrains.gradle.plugin.idea-ext.gradle.plugin:1.1.1"
}
}
apply plugin: 'net.minecraftforge.gradle'
// Only edit below this line, the above code adds and enables the necessary things for Forge to be setup.
apply plugin: 'eclipse'
apply plugin: 'com.github.johnrengelman.shadow'
apply plugin: 'org.parchmentmc.librarian.forgegradle'
apply plugin: 'org.jetbrains.gradle.plugin.idea-ext'
apply plugin: 'org.spongepowered.mixin'
version = buildVersionString()
group = 'blusunrize.immersiveengineering' // http://maven.apache.org/guides/mini/guide-naming-conventions.html
archivesBaseName = 'ImmersiveEngineering'
java.toolchain.languageVersion = JavaLanguageVersion.of(17)
jar.enabled = false
sourceSets {
manual {
compileClasspath = main.compileClasspath
}
api {
compileClasspath = main.compileClasspath
compileClasspath += manual.output
runtimeClasspath += manual.output
}
main {
resources {
srcDirs = [
"$rootDir/src/main/resources",
"$rootDir/src/generated/resources",
]
}
compileClasspath += manual.output + api.output
runtimeClasspath += manual.output + api.output
}
datagen {
compileClasspath += main.compileClasspath
runtimeClasspath += main.runtimeClasspath
compileClasspath += main.output
runtimeClasspath += main.output
}
gametest {
compileClasspath += main.compileClasspath
runtimeClasspath += main.runtimeClasspath
compileClasspath += main.output
runtimeClasspath += main.output
}
test {
compileClasspath += manual.output + api.output
runtimeClasspath += manual.output + api.output
}
}
def version_replaces = [
'version' : project.version,
'mc_version' : version_minecraft,
'forge_version': version_forge,
'jei_version' : version_jei,
]
def jsonPatterns = ["**/*.json", "**/*.mcmeta"]
processResources {
duplicatesStrategy = DuplicatesStrategy.FAIL
inputs.properties(version_replaces)
filesMatching("META-INF/mods.toml") {
expand version_replaces
}
exclude ".cache"
//Minify json resources
doLast {
fileTree(dir: getOutputs().getFiles().getAsPath(), includes: jsonPatterns).each {
File file -> file.setText(JsonOutput.toJson(new JsonSlurper().parse(file, 'UTF-8')))
}
}
}
// When using "Run using IntelliJ" (the only option with well-working hotswapping) the used "resources" directory is
// different from the one used by gradle/the processResources task
task copyModsTomlForIntelliJ(type: Copy) {
from processResources.destinationDir
into "$projectDir/out/production/resources"
include "META-INF/mods.toml"
}
copyModsTomlForIntelliJ.dependsOn processResources
afterEvaluate {
// prepareRuns doesn't exist before afterEvaluate
prepareRuns.dependsOn copyModsTomlForIntelliJ
}
minecraft {
mappings channel: 'parchment', version: version_parchment
runs {
client {
workingDirectory project.file('run')
// Recommended logging data for a userdev environment
property 'forge.logging.markers', 'SCAN'
property 'forge.enabledGameTestNamespaces', 'immersiveengineering'
// Recommended logging level for the console
property 'forge.logging.console.level', 'debug'
// TODO not really ideal, is it?
ideaModule project.name + ".gametest"
mods {
immersiveengineering {
source sourceSets.main
source sourceSets.manual
source sourceSets.api
source sourceSets.gametest
}
}
}
server {
workingDirectory project.file('run')
// Recommended logging data for a userdev environment
property 'forge.logging.markers', ''
// Recommended logging level for the console
property 'forge.logging.console.level', 'debug'
property 'forge.enabledGameTestNamespaces', 'immersiveengineering'
// Disable GUI by default, the IDE console can be used to enter commands
arg '-nogui'
mods {
immersiveengineering {
source sourceSets.main
source sourceSets.api
// Never actually used on the server, but not having it apparently breaks cpw's silly "let's just
// load the wrong supplier in DistExecutor"
source sourceSets.manual
}
}
}
data {
workingDirectory project.file('run')
// Recommended logging data for a userdev environment
property 'forge.logging.markers', ''
// Recommended logging level for the console
property 'forge.logging.console.level', 'debug'
property 'fml.earlyprogresswindow', 'false'
args '--mod', 'immersiveengineering', '--all', '--output', file('src/generated/resources/'), '--validate',
'--existing', sourceSets.main.resources.srcDirs[0]
ideaModule project.name+".datagen"
mods {
immersiveengineering {
source sourceSets.main
source sourceSets.datagen
source sourceSets.manual
source sourceSets.api
}
}
}
gameTestServer {
workingDirectory project.file('run')
property 'forge.logging.markers', ''
property 'forge.logging.console.level', 'debug'
property 'forge.enabledGameTestNamespaces', 'immersiveengineering'
ideaModule project.name + ".gametest"
mods {
immersiveengineering {
source sourceSets.main
source sourceSets.gametest
source sourceSets.manual
source sourceSets.api
}
}
}
}
}
repositories {
maven { // TOP (The one probe)
name 'tterrag maven'
url "https://maven.tterrag.com/"
}
maven { // JEI & Tinkers
name 'DVS1 Maven FS'
url 'https://dvs1.progwml6.com/files/maven'
}
maven { // BlockModelSplitter
name 'Jared maven'
url 'https://maven.blamejared.com/'
}
maven {//Curse maven, in case some other maven goes offline and for mods that don't have a maven
url "https://cfa2.cursemaven.com"
content {
includeGroup "curse.maven"
}
}
maven { // CC-Tweaked
url 'https://squiddev.cc/maven/'
content {
includeGroup 'org.squiddev'
}
}
maven { //Curious
url "https://maven.theillusivec4.top/"
}
}
dependencies {
minecraft "net.minecraftforge:forge:${version_minecraft}-${version_forge}"
compileOnly fg.deobf("mezz.jei:jei-1.18.2:${version_jei}:api")
compileOnly fg.deobf("com.blamejared.crafttweaker:CraftTweaker-forge-1.18.2:9.1.137")
compileOnly fg.deobf("org.squiddev:cc-tweaked-${version_minecraft}:${version_cctweaked}")
compileOnly fg.deobf("curse.maven:the-one-probe-245211:3550084")
compileOnly fg.deobf("top.theillusivec4.curios:curios-forge:1.18-5.0.2.4:api")
compileOnly fg.deobf("curse.maven:jade-324717:3551337")
compileOnly fg.deobf("curse.maven:opencomputers2-437654:3739469")
implementation "malte0811:BlockModelSplitter:2.0.1"
testImplementation('junit:junit:4.13.2')
annotationProcessor 'org.spongepowered:mixin:0.8.5:processor'
}
def customGradle = rootProject.file('custom.gradle');
if (customGradle.exists()) {
apply from: customGradle;
}
task signJar(type: SignJar) {
onlyIf {
project.hasProperty('keyStore')
}
if (project.hasProperty('keyStore')) {
keyStore = project.keyStore
alias = project.storeAlias
storePass = project.storePass
keyPass = project.storePass
inputFile = shadowJar.archiveFile
outputFile = shadowJar.archiveFile
} else {
logger.warn("No key store found, not signing the output jar\n")
}
}
build.dependsOn signJar
afterEvaluate {
signJar.dependsOn reobfShadowJar
reobfJar.enabled = false
}
String buildVersionString() {
String ie_output_version = "${version_ie}-${version_buildnumber}"
boolean jenkins_build = System.getenv("ie_add_git_rev") != null
if (jenkins_build) {
File changelog = new File("changelog.md")
if (!changelog.exists()) {
// Get the current minor/patch number and bump it
int idx = version_ie.lastIndexOf(".")
String major = version_ie.substring(0, idx)
String minor = version_ie.substring(idx + 1)
int bumped = minor.toInteger() + 1
ie_output_version = "${major}.${bumped}-pre"
} else {
// If the changelog file is present, we use the first line from that
String first_line = changelog.readLines().get(0)
ie_output_version = first_line.substring(first_line.indexOf("-") + 1)
}
// Now use describe to get the number of commits since the last tag
exec {
commandLine 'git', 'fetch', '-t'
}
def stdout = new ByteArrayOutputStream()
exec {
commandLine 'git', 'describe', '--long', '--abbrev=8', 'HEAD'
standardOutput = stdout
}
String descr = stdout.toString().trim()
descr = descr.substring(0, descr.length() - 10)
int idx = descr.lastIndexOf("-")
int pre_version = descr.substring(idx + 1).toInteger()
// If there have been more than 0 commits, consider this a pre-build
// otherwise use normal versioning (so a Jenkins build on the tag is equal to a release)
if (pre_version > 0)
ie_output_version = "${ie_output_version}.${pre_version}"
}
return "${version_minecraft}-${ie_output_version}"
}
task datagenJar(type: Jar, dependsOn: datagenClasses) {
classifier = 'datagen'
from sourceSets.datagen.output
manifest {
attributes "FMLModType": "GAMELIBRARY"
}
}
task apiJar(type: Jar, dependsOn: apiClasses) {
classifier = 'api'
from sourceSets.api.output
from sourceSets.manual.output
}
task sourcesJar(type: Jar, dependsOn: classes) {
classifier = 'sources'
from sourceSets.main.allSource
from sourceSets.manual.allSource
from sourceSets.api.allSource
from sourceSets.datagen.allSource
}
artifacts {
archives sourcesJar
archives shadowJar
archives datagenJar
archives apiJar
}
shadowJar {
classifier = ''
dependencies {
include(dependency('malte0811:BlockModelSplitter:.*'))
}
from(sourceSets.manual.output)
from(sourceSets.api.output)
}
reobf {
shadowJar {}
}
//Minimize/optimize all png files, requires optipng on the PATH
// Credits: BrainStone
void minimizePNGFile(File file) {
long size = file.length()
exec {
executable "optipng"
args "-q", "-o7", "-zm1-9", "-strip", "all", file
}
long newSize = file.length()
if (newSize < size) {
System.out.format("Reduced File size of %s from %d bytes to %d bytes (reduced by %.2f%%)\n",
file, size, newSize, ((double) (size - newSize)) / ((double) size) * 100.0)
}
}
task optimizePng {
def pngPatterns = ["**/*.png"]
doLast {
//Ensure the logo is minimized (we add this file to each jar)
//Minimize any PNGs in the source sets
for (dir in sourceSets.main.resources.srcDirs) {
fileTree(dir: dir, includes: pngPatterns).each { minimizePNGFile(it) }
}
}
}
apply plugin: 'maven-publish'
publishing {
repositories {
maven {
url = "file://" + (System.getenv("local_maven") != null ? System.getenv("local_maven") : System.getenv("bamboo_local_maven"))
}
}
publications {
maven(MavenPublication) {
groupId = project.group
version = project.version
artifactId = project.archivesBaseName
artifact sourcesJar
artifact shadowJar
artifact datagenJar
artifact apiJar
pom {
name = project.archivesBaseName
description = project.archivesBaseName
url = 'https://www.curseforge.com/minecraft/mc-mods/immersive-engineering'
scm {
url = 'https://github.com/BluSunrize/ImmersiveEngineering'
connection = 'scm:git:git@github.com/BluSunrize/ImmersiveEngineering.git'
developerConnection = 'scm:git:git@github.com/BluSunrize/ImmersiveEngineering.git'
}
issueManagement {
system = 'github'
url = 'https://github.com/BluSunrize/ImmersiveEngineering/issues'
}
developers {
developer {
id = 'BluSunrize'
name = 'BluSunrize'
}
}
}
}
}
}
publish.dependsOn build
//Code for automatic update JSON generation
abstract class GenerateUpdateJSON extends DefaultTask {
static def initVersions = { mcFromIEVersion ->
mcFromIEVersion.put("0.8", "1.8.9")
mcFromIEVersion.put("0.9", "1.9.4")
mcFromIEVersion.put("0.10", "1.10.2")
mcFromIEVersion.put("0.11", "1.11.2")
mcFromIEVersion.put("0.12", "1.12.2")
mcFromIEVersion.put("0.14", "1.14.4")
mcFromIEVersion.put("0.15", "1.15.2")
mcFromIEVersion.put("0.16", "1.16.1")
}
static def VERSION_PREFIX = "##### Version "
static def BUILT_SUFFIX = " - BUILT"
static def PRE_SUFFIX = "-pre"
static def RECOMMENDED = "-recommended"
static def LATEST = "-latest"
static def CF_URL = "https://minecraft.curseforge.com/projects/immersive-engineering"
@Incremental
@PathSensitive(PathSensitivity.NAME_ONLY)
@InputFile
abstract RegularFileProperty getMarkdown()
@OutputFile
abstract RegularFileProperty getOnlineJSON()
@OutputFile
abstract RegularFileProperty getIncludedJSON()
static int compareVersions(String vA, String vB) {
String[] vPartsA = vA.split("[\\D]")
String[] vPartsB = vB.split("[\\D]")
if (vPartsA.length == 0 && vPartsB.length == 0)
return vA <=> vB
else if (vPartsA.length == 0)
return -1
else if (vPartsB.length == 0)
return 1
int length = Math.min(vPartsA.length, vPartsB.length)
for (int i = 0; i < length; i++) {
int pA = Integer.parseInt(vPartsA[i])
int pB = Integer.parseInt(vPartsB[i])
if (pA != pB) {
return pA <=> pB
}
}
if (vPartsA.length != vPartsB.length)
return vPartsA.length <=> vPartsB.length
return vA <=> vB
}
@TaskAction
def generate() {
Map<String, String> mcFromIEVersion = new HashMap<>()
initVersions(mcFromIEVersion)
File changelog = getMarkdown().get().asFile;
if (!changelog.exists())
println "Changelog does not exist! Aborting!"
else {
Map<String, Map<String, String>> changelogForVersions = new HashMap<>()
Map<String, String> promos = new TreeMap<>({ String s1, String s2 ->
compareVersions(s1, s2)
})
String currentVersion = null
String currentChangelog = ""
changelog.eachLine('ISO-8859-1', { line ->
if (line.startsWith(VERSION_PREFIX)) {
if (currentVersion != null) {
String mainVer = currentVersion.substring(0, currentVersion.indexOf('-'))
String mcVer;
// legacy versioning support
if (mainVer.startsWith("0.")) {
mcVer = mcFromIEVersion[mainVer]
} else {
mcVer = mainVer
}
if (mcVer == null) {
throw new NullPointerException("Could not find MC version for " + currentVersion);
} else if (mcVer == project.ext.version_minecraft) {
if (!changelogForVersions.containsKey(mcVer)) {
promos.put(mcVer + RECOMMENDED, currentVersion)
promos.put(mcVer + LATEST, currentVersion)
changelogForVersions[mcVer] = new TreeMap<>({ String s1, String s2 ->
compareVersions(s1, s2)
})
}
changelogForVersions[mcVer][currentVersion] = currentChangelog
}
}
if (line.endsWith(BUILT_SUFFIX)) {
currentVersion = line.substring(VERSION_PREFIX.length(), line.length() - BUILT_SUFFIX.length())
} else if (!line.endsWith(PRE_SUFFIX)) {
currentVersion = line.substring(VERSION_PREFIX.length())
} else {
currentVersion = (String) null
}
currentChangelog = ""
} else if (!line.isEmpty()) {
if (currentChangelog.length() == 0)
currentChangelog += line
else
currentChangelog += "\n" + line
}
return null
})
Map<String, Object> mainMap = new TreeMap<>({ String s1, String s2 ->
compareVersions(s1, s2)
})
mainMap.putAll(changelogForVersions)
mainMap["homepage"] = CF_URL
mainMap["promos"] = promos
//JSON for the Forge update checker
def updateJson = JsonOutput.toJson(mainMap)
updateJson = JsonOutput.prettyPrint(updateJson)
File outF = getOnlineJSON().get().asFile;
outF.delete()
outF << updateJson
//JSON for the manual
def mapForCurrent = changelogForVersions.getOrDefault(project.ext.version_minecraft, new HashMap<>())
def manualJson = JsonOutput.toJson(mapForCurrent)
manualJson = JsonOutput.prettyPrint(manualJson)
outF = getIncludedJSON().get().asFile;
outF.delete()
outF << manualJson
}
}
}
task updateJson(type: GenerateUpdateJSON) {
markdown = file("changelog.md")
includedJSON = file("src/main/resources/assets/immersiveengineering/changelog.json")
onlineJSON = file("changelog.json")
}
processResources.dependsOn updateJson
mixin {
add sourceSets.main, "${modid}.refmap.json"
config "${modid}.mixins.json"
}
// Running this is equivalent to running genIntellijRuns, but it exists before afterEvaluate
task genIntellijRunsDummy {}
task speedUpPreRun {
doLast {
for (String s : new String[]{"Client", "Server", "Data"}) {
ant.replace(
file: ".idea/runConfigurations/run"+s+".xml",
// prepareRunX is prepareRuns + compile, but compiling is already handled by IntelliJ
token: "prepareRun"+s,
value: "prepareRuns"
)
}
}
}
tasks.withType(Task) {
if (it.name == "genIntellijRuns") {
it.finalizedBy speedUpPreRun
genIntellijRunsDummy.dependsOn it
} else if (it.name == "runServer") {
it.standardInput = System.in
}
}
idea.project.settings.taskTriggers {
afterSync genIntellijRunsDummy
}