forked from SleepyTrousers/EnderIO-1.5-1.12
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.gradle
460 lines (387 loc) · 14.9 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
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
}
}
plugins {
id 'com.matthewprenger.cursegradle' version "1.0.7"
}
apply plugin: 'maven'
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'
// 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://dvs1.progwml6.com/files/maven" }
maven { url = "http://files.minecraftforge.net/maven" }
maven { url = "http://maven.cil.li/" }
maven { url = "http://maven.ic2.player.to" }
maven { url = "http://maven.mcmoddev.com" }
maven { url = "http://mod-buildcraft.com/maven/" }
ivy {
url "http://ae-mod.info/builds"
layout "pattern", {
artifact "[module]-[revision](-[classifier])(.[ext])"
}
}
mavenLocal()
}
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')
}
// 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', '-alias', 'signFiles', '-keystore', 'eiostore.jks', '-storepass', '123456', '-noprompt', '-dname', 'CN='+getCN(), '-keypass', '123456'
}
// 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 rmKeyStore(type: Delete) {
delete 'eiostore.jks'
}
build.dependsOn rmKeyStore
rmKeyStore.dependsOn signJar
signJar.dependsOn mkKeyStore
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 (e.path == 'lib/CoFHLib/src/main/java') {
e.entryAttributes['ignore_optional_problems'] = 'true'
}
}
if (localEnderCore) {
entries.add(new ProjectDependency("/EnderCore"))
}
}
}
}
}
}
// Configuration that applies only to modules
subprojects {
// Assembly an API jar
task apiJar(type: Jar) {
classifier = 'api'
from sourceSets.main.allSource
from sourceSets.main.output
include 'crazypants/enderio/api/**/*'
}
// Assemble a source jar
task sourcesJar(type: Jar) {
classifier = 'sources'
from sourceSets.main.allSource
}
artifacts {
archives apiJar
archives sourcesJar
}
}
// 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
}
}
// Combine all the API jars into a single jar
task combApiJar(type: Jar) {
dependsOn combjarprojects.tasks['classes']
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
combjarprojects.each { subproject ->
from subproject.apiJar
}
}
artifacts {
archives combApiJar
}
// Finally copy all the jars to `libs`
task copyJars(type: Copy, dependsOn: subprojects.tasks['signJar']) {
from buildprojects.collect { it.tasks.withType(Jar) }
into "$buildDir/libs"
}
build.dependsOn copyJars
def release = System.getenv("RELEASE") != null &&
!System.getenv("RELEASE").equalsIgnoreCase("false")
tasks.curseforge.enabled = release && project.hasProperty('curseforge_key')
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 = 'alpha' // for now
mainArtifact(jar) {
displayName = "Ender IO - ${version}"
}
relations {
requiredLibrary 'endercore'
optionalLibrary 'waila'
optionalLibrary 'jei'
optionalLibrary 'the-one-probe'
optionalLibrary 'baubles'
optionalLibrary 'chisel'
optionalLibrary 'hwyla'
optionalLibrary 'opencomputers'
optionalLibrary 'forestry'
optionalLibrary 'ctm'
optionalLibrary 'applied-energistics-2'
optionalLibrary 'actually-additions'
optionalLibrary 'extreme-reactors'
optionalLibrary 'biomes-o-plenty'
optionalLibrary 'botania'
optionalLibrary 'buildcraft'
optionalLibrary 'chisels-bits'
optionalLibrary 'extra-utilities'
optionalLibrary 'immersive-engineering'
optionalLibrary 'industrial-craft'
optionalLibrary 'natura'
optionalLibrary 'thermal-foundation'
optionalLibrary 'tinkers-construct'
}
buildprojects.each { subproject ->
addArtifact subproject.jar
if (resolveOption(subproject, 'publish_api'))
addArtifact subproject.apiJar
if (resolveOption(subproject, 'publish_source'))
addArtifact subproject.sourceJar
}
}
}
// 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 getArchiveBaseName(Project proj) {
def project_base_name = rootProject.name
if (proj.hasProperty('module_name'))
project_base_name += "-${proj.module_name}"
return "${project_base_name}-${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
}