forked from BluSunrize/ImmersiveEngineering
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.gradle
434 lines (399 loc) · 14.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
import groovy.json.JsonOutput
import groovy.json.JsonSlurper
import net.fabricmc.loom.task.RemapJarTask;
import org.gradle.work.Incremental
// TODO any missing custom features?
plugins {
id 'dev.architectury.loom' version '0.10.0-SNAPSHOT'
id 'maven-publish'
id 'com.github.johnrengelman.shadow' version '7.0.0'
}
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
archivesBaseName = 'ImmersiveEngineering'
version = buildVersionString()
group = 'blusunrize.immersiveengineering'
sourceSets {
manual {
compileClasspath = main.compileClasspath
}
api {
compileClasspath = main.compileClasspath
compileClasspath += manual.output
runtimeClasspath += manual.output
}
main {
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 += main.compileClasspath + manual.output + api.output
runtimeClasspath += main.runtimeClasspath + manual.output + api.output
}
}
loom {
silentMojangMappingsLicense()
runs {
data {
source sourceSets.datagen
data()
}
}
forge {
mixinConfigs = [
//TODO constant, and fix silly cast errors
"immersiveengineering.mixins.json"
]
dataGen {
mod project.modid
}
localMods.clear()
localMods {
immersiveengineering {
add project.sourceSets.main
add project.sourceSets.manual
add project.sourceSets.api
add project.sourceSets.datagen
}
}
launches {
data {
arg "--existing", file("src/main/resources").absolutePath
}
}
}
}
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://cursemaven.com"
content {
includeGroup "curse.maven"
}
}
maven { // CC-Tweaked
url 'https://squiddev.cc/maven/'
}
maven { //Curious
url "https://maven.theillusivec4.top/"
}
}
dependencies {
minecraft "com.mojang:minecraft:${project.version_minecraft}"
mappings minecraft.officialMojangMappings()
forge "net.minecraftforge:forge:${project.version_minecraft}-${project.version_forge}"
modCompileOnly "mezz.jei:jei-1.16.5:7.7.1.121:api"
modCompileOnly "org.squiddev:cc-tweaked-1.16.4:1.94.0"
modCompileOnly "mcjty.theoneprobe:TheOneProbe-1.16:1.16-3.+"
modCompileOnly "top.theillusivec4.curios:curios-forge:1.16.5-4.0.4.0:api"
modCompileOnly group: "com.blamejared.crafttweaker", name: "CraftTweaker-1.16.5", version: "7.1.0.245"
modCompileOnly "curse.maven:jade-324717:3467445"
testImplementation('junit:junit:4.13')
implementation "malte0811:BlockModelSplitter:1.2.0"
}
def customGradle = rootProject.file('custom.gradle');
if (customGradle.exists()) {
apply from: customGradle;
}
def version_replaces = [
'version': project.version,
'mc_version': version_minecraft,
'forge_version': version_forge
]
def jsonPatterns = ["**/*.json", "**/*.mcmeta"]
processResources {
duplicatesStrategy = DuplicatesStrategy.FAIL
filesMatching("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')))
}
}
}
java {
withSourcesJar()
}
shadowJar {
classifier = 'shadow'
dependencies {
include(dependency('malte0811:BlockModelSplitter:.*'))
}
from(sourceSets.manual.output)
from(sourceSets.api.output)
}
remapJar {
dependsOn(shadowJar)
input = shadowJar.archiveFile
classifier ""
}
//TODO remap datagen&API
task datagenJar(type: Jar, dependsOn: datagenClasses) {
classifier = 'datagen-dev'
from sourceSets.datagen.output
manifest {
attributes "FMLModType": "LIBRARY"
}
}
task apiJar(type: Jar, dependsOn: apiClasses) {
classifier = 'api-dev'
from sourceSets.api.output
from sourceSets.manual.output
}
task remapDatagenJar(type: RemapJarTask, dependsOn: datagenJar) {
classifier = 'datagen'
input = datagenJar.archiveFile
addNestedDependencies = false
}
task remapApiJar(type: RemapJarTask, dependsOn: apiJar) {
classifier = 'api'
input = apiJar.archiveFile
addNestedDependencies = false
}
tasks.withType(JavaCompile).configureEach {
it.options.encoding = "UTF-8"
def targetVersion = 8
if (JavaVersion.current().isJava9Compatible()) {
it.options.release = targetVersion
}
}
task signJar(description: "Sign jar") {
doLast {
if (project.hasProperty('keyStore')) {
def path = remapJar.archivePath
logger.info("Signing " + path + "\n")
ant.signjar(jar: path,
alias: project.storeAlias,
keystore: project.keyStore,
storepass: project.storePass,
keypass: project.storePass
)
} 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', '--force', '--tags'
}
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}"
}
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 remapJar
artifact remapDatagenJar
artifact remapApiJar
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:[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'
}
}
}
}
}
}
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);
}
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