forked from BluSunrize/ImmersiveEngineering
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.gradle
537 lines (483 loc) · 18.4 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
import groovy.json.JsonOutput
import groovy.json.JsonSlurper
import net.minecraftforge.gradle.common.task.SignJar
buildscript {
repositories {
mavenLocal()
maven { url = 'https://maven.minecraftforge.net' }
maven {url "https://plugins.gradle.org/m2/"}
mavenCentral()
maven {url='https://repo.spongepowered.org/repository/maven-public/'}
}
dependencies {
classpath group: 'net.minecraftforge.gradle', name: 'ForgeGradle', version: '4.1.+', changing: true
classpath 'com.github.jengelman.gradle.plugins:shadow:4.0.0'
classpath 'org.spongepowered:mixingradle:0.7-SNAPSHOT'
}
}
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: 'maven-publish'
apply plugin: 'com.github.johnrengelman.shadow'
version = buildVersionString()
group = 'blusunrize.immersiveengineering' // http://maven.apache.org/guides/mini/guide-naming-conventions.html
archivesBaseName = 'ImmersiveEngineering'
sourceCompatibility = targetCompatibility = compileJava.sourceCompatibility = compileJava.targetCompatibility = '1.8' // Need this here so eclipse task generates correctly.
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
}
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
]
def jsonPatterns = ["**/*.json", "**/*.mcmeta"]
processResources {
duplicatesStrategy = DuplicatesStrategy.FAIL
exclude 'META-INF/mods.toml'
from(sourceSets.main.resources.srcDirs) {
include 'META-INF/mods.toml'
expand version_replaces
}
//Minify json resources
doLast {
fileTree(dir: getOutputs().getFiles().getAsPath(), includes: jsonPatterns).each {
File file -> file.setText(JsonOutput.toJson(new JsonSlurper().parse(file, 'UTF-8')))
}
}
}
task replaceInModsToml(type: Copy) {
outputs.upToDateWhen { false }
from(sourceSets.main.resources) {
include "META-INF/mods.toml"
expand version_replaces
}
into "$buildDir/resources/main/"
}
// 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 copyResourcesForIntelliJ(type: Copy) {
from processResources.destinationDir
into "$projectDir/out/production/resources"
}
processResources.finalizedBy replaceInModsToml, copyResourcesForIntelliJ
minecraft {
mappings channel: 'snapshot', version: "${version_mcp}"
runs {
client {
workingDirectory project.file('run')
// Recommended logging data for a userdev environment
property 'forge.logging.markers', ''
property 'fml.earlyprogresswindow', 'false'
property 'mixin.env.disableRefMap', 'true'
// Recommended logging level for the console
property 'forge.logging.console.level', 'debug'
arg "-mixin.config="+modid+".mixins.json"
mods {
immersiveengineering {
source sourceSets.main
source sourceSets.manual
source sourceSets.api
}
}
}
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 'mixin.env.disableRefMap', 'true'
// Disable GUI by default, the IDE console can be used to enter commands
arg '-nogui'
arg "-mixin.config="+modid+".mixins.json"
mods {
immersiveengineering {
source sourceSets.main
source sourceSets.api
}
}
}
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'
property 'mixin.env.disableRefMap', 'true'
args '--mod', 'immersiveengineering', '--all', '--output', file('src/generated/resources/'), '--validate',
'--existing', sourceSets.main.resources.srcDirs[0]
arg "-mixin.config="+modid+".mixins.json"
ideaModule project.name+".datagen"
mods {
immersiveengineering {
source sourceSets.main
source sourceSets.datagen
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/'
}
repositories {//Curseforge maven, in case some other maven goes offline and for mods that don't have a maven
maven {
name = "CurseForge"
url = "https://minecraft.curseforge.com/api/maven/"
}
}
maven { // CC-Tweaked
url 'https://squiddev.cc/maven/'
}
maven { //Curious
url "https://maven.theillusivec4.top/"
}
}
dependencies {
minecraft "net.minecraftforge:forge:${version_minecraft}-${version_forge}"
compileOnly fg.deobf("mezz.jei:jei-1.16.5:7.6.1.75:api")
compileOnly fg.deobf("org.squiddev:cc-tweaked-1.16.4:1.94.0")
compileOnly fg.deobf("mcjty.theoneprobe:TheOneProbe-1.16:1.16-3.+")
compileOnly fg.deobf("top.theillusivec4.curios:curios-forge:1.16.5-4.0.4.0:api")
compile "malte0811:BlockModelSplitter:1.2.0"
testImplementation('junit:junit:4.13')
annotationProcessor 'org.spongepowered:mixin:0.8.2:processor'
compileOnly fg.deobf(group: "com.blamejared.crafttweaker", name: "CraftTweaker-1.16.5", version: "7.1.0.245")
}
def customGradle = rootProject.file('custom.gradle');
if (customGradle.exists()) {
apply from: customGradle;
}
def reobfFile = file("$buildDir/reobfJar/output.jar")
def reobfArtifact = artifacts.add('default', reobfFile) {
type 'jar'
builtBy 'reobfJar'
}
task signJar(type: SignJar, dependsOn: jar) {
onlyIf {
project.hasProperty('keyStore')
}
if (project.hasProperty('keyStore')) {
keyStore = project.keyStore
alias = project.storeAlias
storePass = project.storePass
keyPass = project.storePass
inputFile = jar.archivePath
outputFile = jar.archivePath
} else {
logger.warn("No key store found, not signing the output jar\n")
}
}
build.dependsOn signJar
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": "LIBRARY"
}
}
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) }
}
}
}
jar {
manifest {
attributes([
"MixinConfigs": "${modid}.mixins.json"
])
}
}
apply plugin: 'maven'
uploadArchives {
repositories {
mavenDeployer {
repository(url: "file://" + (System.getenv("local_maven") != null ? System.getenv("local_maven") : System.getenv("bamboo_local_maven")))
pom {
groupId = project.group
version = project.version
artifactId = project.archivesBaseName
project {
name project.archivesBaseName
packaging 'jar'
description project.archivesBaseName
url ''
scm {
url 'https://github.com/BluSunrize/ImmersiveEngineering'
connection 'scm:git:[email protected]/BluSunrize/ImmersiveEngineering.git'
developerConnection 'scm:git:[email protected]/BluSunrize/ImmersiveEngineering.git'
}
issueManagement {
system 'github'
url 'https://github.com/BluSunrize/ImmersiveEngineering/issues'
}
developers {
developer {
id 'BluSunrize'
name 'BluSunrize'
roles { role 'developer' }
}
}
}
}
}
}
}
uploadArchives.dependsOn build
//Code for automatic update JSON generation
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 CHANGELOG_FOR_MANUAL = "src/main/resources/assets/immersiveengineering/changelog.json"
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"
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 = new File("changelog.md")
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);
}
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 = new File("changelog.json")
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 = new File(CHANGELOG_FOR_MANUAL)
outF.delete()
outF << manualJson
}
}
}
task updateJson(type: GenerateUpdateJSON)
processResources.dependsOn updateJson
apply plugin: 'org.spongepowered.mixin'
mixin {
add sourceSets.main, "${modid}.refmap.json"
}
// Prevent Mixin annotation processor from getting into IDEA's annotation processor settings
// Copied from Botania
if (System.getProperty("idea.sync.active") == "true") {
afterEvaluate {
tasks.withType(JavaCompile).all {
it.options.annotationProcessorPath = files()
}
}
}