forked from SleepyTrousers/EnderIO-1.5-1.12
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.gradle
568 lines (481 loc) · 20 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
buildscript {
repositories {
jcenter()
mavenCentral()
maven {
name = "forge"
url = "http://files.minecraftforge.net/maven"
}
maven {
url "https://plugins.gradle.org/m2/"
}
}
dependencies {
classpath 'net.minecraftforge.gradle:ForgeGradle:2.3-SNAPSHOT'
classpath "gradle.plugin.net.intellisun:modDependencies:1.0.1-alpha.2" // https://github.com/IntelliSun-MC/modDependencies
classpath 'org.junit.platform:junit-platform-gradle-plugin:1.0.3'
classpath "com.vladsch.flexmark:flexmark:0.34.52"
classpath "com.vladsch.flexmark:flexmark-pdf-converter:0.34.52"
}
}
plugins {
id 'com.matthewprenger.cursegradle' version "1.1.0"
id "com.dorongold.task-tree" version "1.3"
}
apply plugin: 'eclipse'
// We use these to mess with the eclipse .classpath file
import org.gradle.plugins.ide.eclipse.model.AbstractClasspathEntry
import org.gradle.plugins.ide.eclipse.model.ProjectDependency
// More user properties
ext.user = parseConfig(file('user.properties'))
if (ext.user != null) {
ext.user.each { k, v ->
project.ext.set(k, v)
}
}
// Configure all projects
allprojects {
apply plugin: 'net.minecraftforge.gradle.forge'
apply plugin: 'net.intellisun.moddependencies'
apply plugin: 'org.junit.platform.gradle.plugin'
// Import mod dependencies and execute
if (file('dependencies.gradle').exists())
apply from: 'dependencies.gradle'
group = 'com.enderio'
version = getVersionString(project)
archivesBaseName = getArchiveBaseName(project)
// Configure minecraft pipline
minecraft {
version = "${minecraft_version}-${forge_version}"
mappings = mcp_mappings
runDir = "run"
// Replace the version string in source
replace '@VERSION@', project.version
// If the module defines `dependencyString` use it
if (project.hasProperty('dependencyString'))
replace 'DEFAULT_DEPENDENCIES;', "\"${dependencyString}\";"
}
// The is very temporary, currently not all modules compile
// This will exclude all non compiling modules from CI but
// they will still appear is IDEs.
// TODO: Remove this once all modules compile
if (!project.hasProperty('include_in_build'))
project.ext.include_in_build = true
else
project.include_in_build = project.include_in_build != 'false'
if (!project.hasProperty('include_in_combjar'))
project.ext.include_in_combjar = true
else
project.ext.include_in_combjar = project.include_in_combjar != 'false'
project.ext.include_in_combjar = project.ext.include_in_combjar && project.include_in_build
// Eclipse needs this for some reason
sourceCompatibility = targetCompatibility = JavaVersion.VERSION_1_8
compileJava {
sourceCompatibility = targetCompatibility = JavaVersion.VERSION_1_8
}
repositories {
mavenCentral()
maven { url = "http://tehnut.info/maven" }
maven { url = "http://maven.tterrag.com" }
maven { url = "http://maven2.tterrag.com" }
maven { url = "http://dvs1.progwml6.com/files/maven" }
maven { url = "http://files.minecraftforge.net/maven" }
maven { url = "http://maven.cil.li/" } // OpenComputers
maven { url = "http://maven.ic2.player.to" }
maven { url = "http://maven.mcmoddev.com" }
maven { url = "http://mod-buildcraft.com/maven/" }
maven { url = "https://maven.latmod.com" } // FTBLib
maven { url = "http://maven.covers1624.net/" } // CoFHCore
maven { url = "http://cc.crzd.me/maven/" } // ComputerCraft
maven { url = "https://repo.raoulvdberge.com/" } // Refined Storage (new)
mavenLocal()
}
configurations {
// configuration that holds jars to embed inside the jar
embed
}
junitPlatform {
platformVersion '1.0.3'
enableStandardTestTask true
}
def localEnderCore = project.hasProperty('use_local_ender_core') && project.getProperty('use_local_ender_core').equalsIgnoreCase('true')
// Common dependencies for all modules
dependencies {
// Remote / local endercore
if (!localEnderCore) {
deobfCompile "com.enderio.core:EnderCore:${endercore_version}"
}
// All jars in the '<module>/lib' directory
compile fileTree(dir: "lib", include: '*.jar')
// All jars in the '<root>/lib' directory
compile fileTree(dir: "${project.rootDir}/lib", include: '*.jar')
testImplementation "org.junit.jupiter:junit-jupiter-api:5.2.0"
testCompile("org.junit.jupiter:junit-jupiter-api:5.2.0")
testCompile("org.junit.platform:junit-platform-launcher:1.1.0")
testRuntime("org.junit.jupiter:junit-jupiter-engine:5.2.0")
}
// Process resources to inject dynamic metadata
processResources {
// Rerun this step every time these change
inputs.property "version", project.version
inputs.property "mcversion", project.minecraft.version
// Inject version and mcversion to mod info
from(sourceSets.main.resources.srcDirs) {
include '**/*.info'
include '**/*.properties'
expand 'version': project.version, 'mcversion': project.minecraft.version
}
// Include everything else as is
from(sourceSets.main.resources.srcDirs) {
exclude '**/*.info'
exclude '**/*.properties'
}
}
// Java 8 throws errors about jdoc, ignore them
if (JavaVersion.current().isJava8Compatible()) {
tasks.withType(Javadoc) {
options.addStringOption('Xdoclint:none', '-quiet')
}
}
// Build the key store for jar signing
task mkKeyStore(type: Exec) {
workingDir projectDir
commandLine 'keytool', '-genkey', '-storetype', 'PKCS12', '-alias', 'signFiles', '-keystore', 'eiostore.jks', '-storepass', '123456', '-noprompt', '-dname', 'CN='+getCN(), '-keypass', '123456'
}
// Convert the core recipes to pdf so the users won't have editable recipe files in their
// config folder. Crude, but it prevents a common mistake. BTW, setting those files to
// read-only works in theory, but all common launchers fail to handle read-only files
// correctly.
processResources.doLast {
def resdir = new File(project.sourceSets.main.output.resourcesDir, "assets/enderio/config/recipes")
project.fileTree([dir: resdir, include: '*.xml']).files.each { file ->
def baseFilename = file.name.take(file.name.lastIndexOf('.'))
def inputFile = new File(resdir, "${baseFilename}.xml")
def outputFile = new File(resdir, "${baseFilename}.pdf")
com.vladsch.flexmark.pdf.converter.PdfConverterExtension.exportToPdf(outputFile.path,
"<html><head></head><body><div style='white-space:pre-wrap; font-family:monospace;'>" +
groovy.xml.XmlUtil.escapeXml(inputFile.text) +
"</div></body></html>", "", new com.vladsch.flexmark.util.options.MutableDataSet())
}
}
// Sign the jar with the new key store
task signJar(type: SignJar, dependsOn: reobfJar) {
inputFile = jar.archivePath
outputFile = jar.archivePath
keyStore = 'eiostore.jks'
alias = 'signFiles'
storePass = '123456'
keyPass = '123456'
}
// Cleanup the keystore
task rmKeyStorePre(type: Delete) {
delete 'eiostore.jks'
}
// Cleanup the keystore
task rmKeyStore(type: Delete) {
delete 'eiostore.jks'
}
build.dependsOn rmKeyStore
rmKeyStore.dependsOn signJar
signJar.dependsOn mkKeyStore
mkKeyStore.dependsOn rmKeyStorePre
eclipse {
classpath {
containers 'org.eclipse.buildship.core.gradleclasspathcontainer'
file {
whenMerged {
entries.each { e ->
if (e.path.contains('gradleclasspathcontainer') || e.path.contains('org.eclipse.jdt.launching.JRE_CONTAINER')) {
// Safety check that EC exists, otherwise we can't add this without breaking eclipse setup
e.entryAttributes['annotationpath'] = localEnderCore ? '/EnderCore/externalannotations' : null
}
}
if (localEnderCore) {
entries.add(new ProjectDependency("/EnderCore"))
}
}
}
}
}
if (project.curse_projectId?.trim())
curseforge {
if (project.hasProperty('curseforge_key')) {
apiKey = project.curseforge_key
}
def build_number = System.getenv('BUILD_NUMBER') == null ? '0' : System.getenv('BUILD_NUMBER')
def changelog_content = System.getenv('CHANGELOG') != null && !System.getenv('CHANGELOG').equals('none') ? System.getenv('CHANGELOG') : ''
def changelog_text = getChangelogFormat()
.replaceAll('#BUILD#', build_number)
.replaceAll('#EXTRA#', changelog_content)
project {
id = project.curse_projectId
changelog = changelog_text
changelogType = 'html'
releaseType = 'release'
mainArtifact(jar) {
String display_addon = project.hasProperty('curse_display_name') ? project.curse_display_name : "Ender IO";
displayName = "${display_addon} - ${version}"
}
relations {
if (project.hasProperty('curse_optional_libraries'))
project.curse_optional_libraries.split(/,\s*/).findAll { it?.trim() }.each { slug -> optionalLibrary slug }
if (project.hasProperty('curse_required_libraries'))
project.curse_required_libraries.split(/,\s*/).findAll { it?.trim() }.each { slug -> requiredLibrary slug }
}
afterEvaluate {
// Work around https://github.com/matthewprenger/CurseGradle/issues/20
gameVersionStrings.remove('Java 9')
// (1) Work around cursegradle setting dependencies for the curseforgeXXX tasks to :subproject:jar and :reobfJar -> force :subproject:reobfJar instead.
// (2) Depend on rmKeyStore instead of reobfJar so the signed jar is uploaded.
// (3) It is very tricky to not run too early (before cursegradle creates the upload task), that's why this looks so convoluted...
allprojects { p ->
p.curseforge.curseProjects.findAll { it.uploadTask }.findAll { it.uploadTask.projectId == p.curse_projectId }.each { curseProject ->
Task reobfTask = p.tasks.findByName('rmKeyStore')
// println "Forcing dependency of ${curseProject.uploadTask} to ${reobfTask}"
curseProject.uploadTask.dependsOn.clear()
curseProject.uploadTask.dependsOn reobfTask
}
}
}
}
}
}
// Configuration that applies only to modules
subprojects {
jar {
into('/META-INF/libraries') {
from configurations.embed
}
doFirst {
manifest {
def contained = configurations.embed.collect { it.getName() };
if (!contained.isEmpty()) {
attributes([
"ContainedDeps": contained.join(' ')
])
}
}
}
}
// Assembly an API jar
task apiJar(type: Jar) {
classifier = 'api'
from sourceSets.main.output.classesDirs
include 'crazypants/enderio/api/**/*'
}
// Assemble a source jar
task sourcesJar(type: Jar) {
classifier = 'sources'
from sourceSets.main.java
}
}
// Part of the temporary fix for not compiling modules
def buildprojects = subprojects.findAll { sp -> sp.include_in_build }
def combjarprojects = subprojects.findAll { sp -> sp.ext.include_in_combjar }
// Make sure all modules are configured
buildprojects.each { subproject -> evaluationDependsOn( subproject.path ) }
jar.doFirst {
// This code merge all resources that are duplicated across the modules.
// Since modules are shiped both as separate modules and as an 'all' jar
// some manifest files are duplicated.
File target = new File(project.sourceSets.main.output.resourcesDir, "assets/enderio/lang")
target.mkdirs()
combjarprojects.each { subproject ->
File langDir = new File(subproject.sourceSets.main.output.resourcesDir, 'assets/enderio/lang/')
if (langDir.exists()) {
langDir.eachFileMatch( ~".*\\.lang\$" ) { langfile ->
new File(target, langfile.name) << langfile.text << "\n"
}
}
}
def mcmod = ""
combjarprojects.each { subproject ->
mcmod += new File(subproject.sourceSets.main.output.resourcesDir, 'mcmod.info').text
}
new File(project.sourceSets.main.output.resourcesDir, "mcmod.info") << mcmod.replaceAll(/\]\s*\[/, ',')
def sound = ""
combjarprojects.each { subproject ->
File soundFile = new File(subproject.sourceSets.main.output.resourcesDir, 'assets/enderio/sounds.json')
if (soundFile.exists()) {
sound += soundFile.text
}
}
new File(project.sourceSets.main.output.resourcesDir, "assets/enderio/sounds.json") << sound.replaceAll(/\}\s*\{/, ',')
println "Created derived resources in ${target}"
}
// Collect all sources from the modules and merge them
// into the all jar.
jar.dependsOn combjarprojects.tasks['classes']
jar {
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
combjarprojects.each { subproject ->
from subproject.sourceSets.main.output.classesDirs
from subproject.sourceSets.main.output.resourcesDir
into('/META-INF/libraries') {
from subproject.configurations.embed
}
}
doFirst {
manifest {
attributes([
"ContainedDeps": combjarprojects.collect { it.configurations.embed.collect { it.getName() }}.flatten().join(' ')
])
}
}
}
sourceJar {
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
combjarprojects.each { subproject ->
from subproject.sourceSets.main.java
}
}
// Copy all the jars to `libs`
task copyJars(type: Copy, dependsOn: subprojects.tasks['signJar']) {
from buildprojects.collect { it.tasks.withType(Jar) }
into "$buildDir/libs"
}
// Combine all the API jars into a single jar
task combApiJar(type: Jar) {
dependsOn copyJars
classifier 'api'
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
combjarprojects.each { subproject ->
from zipTree(subproject.apiJar.getArchivePath()).asFileTree
}
}
artifacts {
archives combApiJar
}
build.dependsOn sourceJar, combApiJar
apply plugin: 'maven-publish'
publishing {
tasks.publish.dependsOn 'build'
publications {
mavenJava(MavenPublication) {
from components.java //Define the properties of the publication
version minecraft_version + "-" + project.version
artifact sourceJar
artifact combApiJar
pom.withXml { //Here we can add custom nodes to the pom file
def dependenciesNode = asNode().getAt("dependencies")[0]
if (dependenciesNode == null) {
dependenciesNode = asNode().appendNode('dependencies')
}
//Iterate over the compile dependencies (we don't want the test ones), adding a <dependency> node for each
configurations.compile.allDependencies.each {
if (!it.name.equals("unspecified")) { //filter out the garbage
def dependencyNode = dependenciesNode.appendNode('dependency')
dependencyNode.appendNode('groupId', it.group)
dependencyNode.appendNode('artifactId', it.name)
dependencyNode.appendNode('version', it.version)
}
}
}
}
}
repositories {
if (project.hasProperty('maven2_url')) {
if (project.hasProperty('maven2_user') && project.hasProperty('maven2_pass')) {
maven {
url maven2_url
credentials {
username maven2_user
password maven2_pass
}
}
} else {
maven { url maven2_url }
}
} else {
mavenLocal()
}
}
}
def release = System.getenv("RELEASE") != null &&
!System.getenv("RELEASE").equalsIgnoreCase("false")
tasks.curseforge.enabled = release && project.hasProperty('curseforge_key')
// Part of the temporary fix for not compiling modules
gradle.taskGraph.whenReady {
def tasksToDisable = [
'build', 'compileJava', 'assemble', 'sourceJar',
'check', 'reobfJar', 'signJar'
]
gradle.taskGraph.allTasks.each {
if(!it.project.include_in_build) {
if (tasksToDisable.find { n -> it.name == n } != null) it.enabled = false
}
}
}
// Generate a random cmmon name for the cert
String getCN() {
def firsts = ['Donald', 'Lex', 'The', 'Arthur', 'Bridget', 'Dorian', 'Ford', 'Guy', 'James', 'Jessica', 'John', 'Michael', 'Robinson', 'Zaphod', 'Bell', 'Penelope']
def lasts = ['Duck', 'Luthor', 'Doctor', 'Master', 'Dent', 'Jones', 'Gray', 'Prefect', 'Montag', 'Moriarty', 'Rabbit', 'Watson', 'Smith', 'Corleone', 'Crusoe', 'Beeblebrox', 'Cranel', 'Akk']
def rand = new Random()
return firsts[rand.nextInt(firsts.size())] + ' ' + lasts[rand.nextInt(lasts.size())]
}
// This is the new version/module format:
// module name:
// enderio-<name>-<mc-version>-<version>
// version:
// <major>.<minor>.<patch>-<cls>-<hash>
// patch:
// defaults to 'version_patch'
// overriten by CI / build server
// cls (classifier):
// * nightly
// * dev
// * ci
// * snapshot
// * etc.
// hash:
// if on a dev machine - the current commit hash
// Examples:
// * enderio-base-1.12.2-4.0.1.jar :: release version 4.0.1 for mc 1.12.2
// * enderio-base-1.12.2-4.2.1-nightly-4 :: nightly build no. 4 for version 4.2.1
// * enderio-base-1.12.2-4.5.1-dev-c91c8ee6e :: dev (local) build for commit c91c8ee6e
String getVersionString(Project proj) {
def build_server = System.getenv('CI') != null || System.getenv('BUILD_NUMBER') != null
def version_patch_lc = proj.version_patch
if (System.getenv('BUILD_NUMBER') != null)
version_patch_lc = System.getenv('BUILD_NUMBER')
def version_classifier = ''
if (System.getenv('VERSION_CLS') != null)
version_classifier = System.getenv('VERSION_CLS')
else if (System.getenv('NIGHTLY') != null)
version_classifier = 'nightly'
def version_hash = ''
if (!build_server) {
try {
version_hash = "git rev-parse --short HEAD".execute().text.trim()
} catch (all) { }
}
def version_base = "${proj.version_major}.${proj.version_minor}.${version_patch_lc}"
def version_parts = ([ version_base, version_classifier, version_hash ]).findAll { p -> p != '' }
return String.join('-', version_parts)
}
String getPrettyName(Project proj) {
def project_base_name = rootProject.name
if (proj.hasProperty('module_name'))
project_base_name += "-${proj.module_name}"
return project_base_name
}
String getArchiveBaseName(Project proj) {
return getPrettyName(proj) + "-${project.minecraft_version}"
}
String getChangelogFormat() {
return new File(projectDir, 'doc/changelog.html').getText('UTF-8')
}
// parse and import external config
def parseConfig(File config) {
if (!config.exists())
return null
config.withReader {
def prop = new Properties()
prop.load(it)
return (new ConfigSlurper().parse(prop))
}
}
def resolveOption(Project project, String option, boolean defaultValue = false) {
def sourceValue = project.hasProperty(option) ? project.property(option) : defaultValue
return sourceValue == 'true' || sourceValue == true || sourceValue == 1
}