forked from BuildCraft/BuildCraft
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.gradle
560 lines (479 loc) · 16.7 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
/*
* Copyright (c) 2017 SpaceToad and the BuildCraft team
* This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was not
* distributed with this file, You can obtain one at https://mozilla.org/MPL/2.0/
*/
/* Build info:
- Using a release version (e.g. 8.0.4 rather than 8.0.4-SNAPSHOT or 8.0.4-0A1B2C3D4E5) requires setting the "release" system property to true
- Add "-Drelease=true" to disallow adding the git commit hash to the end, or SNAPSHOT if we cannot find our git directory.
*/
// DON'T TOUCH THE BUILDSCRIPT[] BLOCK
// its special, and it is only there to make ForgeGradle work correctly.
buildscript {
repositories {
mavenCentral()
jcenter()
maven {
url = "http://files.minecraftforge.net/maven"
}
maven {
name = "sonatype"
url = "https://oss.sonatype.org/content/repositories/snapshots/"
}
maven {
url "https://plugins.gradle.org/m2/"
}
}
dependencies {
classpath "net.minecraftforge.gradle:ForgeGradle:2.3-SNAPSHOT"
classpath "org.ajoberstar:grgit:2.2.1"
}
}
apply plugin: "net.minecraftforge.gradle.forge" // adds the forge dependency
apply plugin: 'maven' // for uploading to a maven repo
apply plugin: 'maven-publish' // for uploading to a maven repo
if (!hasProperty("grgit")) {
// As otherwise it logs a warning as grgit gets applied twice
apply plugin: "org.ajoberstar.grgit"
}
if (gradle.startParameter.taskNames.contains("checkstyle")) {
apply plugin: "checkstyle"
}
ext.configFile = file "build.properties"
configFile.withReader {
// Load config. It shall from now be referenced as simply config or project.config
def prop = new Properties()
prop.load(it)
project.ext.config = new ConfigSlurper().parse prop
}
if (System.getenv("BUILD_NUMBER") != null) {
config.mod_version += "-${System.getenv("BUILD_NUMBER")}"
}
if (System.getenv("BUILD_VARIANT") != null) {
config.mod_version += "-${System.getenv("BUILD_VARIANT")}"
}
version = config.mod_version
group= "com.mod-buildcraft"
archivesBaseName = "buildcraft" // the name that all artifacts will use as a base. artifacts names follow this pattern: [baseName]-[appendix]-[version]-[classifier].[extension]
ext.mcModInfo = new groovy.json.JsonSlurper().parse(file("buildcraft_resources/mcmod.info"))
ext.priv = parseConfig(file('private.properties'))
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
dependencies {
// Testing
testCompile "junit:junit:4.12"
}
minecraft {
version = config.mc_version + "-" + config.forge_version
runDir = "run"
// the mappings can be changed at any time, and must be in the following format.
// snapshot_YYYYMMDD snapshot are built nightly.
// stable_# stables are built at the discretion of the MCP team.
// Use non-default mappings at your own risk. they may not always work.
// simply re-run your setup task after changing the mappings to update your workspace.
mappings = config.mappings_version
// makeObfSourceJar = false // an Srg named sources jar is made by default. uncomment this to disable.
def addVersionDetails = !Boolean.getBoolean("release")
// Git versioning stuffs
if (grgit != null) {
String gitDir;
if (rootProject == project) {
gitDir = "$projectDir";
} else {
File dotGit = project.file(".git");
if (dotGit.isDirectory()) {
gitDir = dotGit;
} else {
gitDir = rootProject.file(".git/modules/BuildCraft").toString()
}
}
def repo = grgit.open(dir: gitDir)
replace "\${git_commit_hash}", repo.head().id
// This is very ugly: we need 7(!) \ to produce a single \ in the final one.
replace "\${git_commit_msg}", repo.head().fullMessage.replace("\"", "\\\\\\\"").split("\n")[0]
replace "\${git_commit_author}", repo.head().author.name
replace "\${git_branch}", repo.branch.current().getName()
if (addVersionDetails) {
// Always use the compat commit for the version.
project.version += "-" + grgit.open(dir: project.rootDir).head().id.toString().substring(0, 12)
}
} else {
if (addVersionDetails) {
project.version += "-SNAPSHOT"
}
}
// replacing stuff in the source
replace "\$version", project.version
replace "\${mcversion}", version
// Replace @Mod.acceptedMinecraftVersions specially as it has to be a valid version in a dev environment :/
replace "(gradle_replace_mcversion,)", "[" + version + "]"
replace "(gradle_replace_forgeversion,)", "[" + config.forge_version + ",)"
}
task printVersion {
description = "Prints out the actual version used. Useful for testing the buildscript. (Add -Drelease=true to force this to the version specified in build.properties)"
doLast {
println "Version = " + project.version
}
}
// configure the source folders
sourceSets {
main {
java {
srcDir "common"
srcDir "common_old_license"
srcDir "sub_projects/expression/src/main/java"
srcDir "sub_projects/expression/src/autogen/java"
// srcDir "src_old_license"
}
resources {
srcDir "buildcraft_resources"
srcDir "BuildCraft-Localization"
exclude "**/.md" // exclude readme from localization repo
srcDir "BuildCraftGuide/guide_resources"
exclude "pack.png" // exclude from the guide repo
exclude "pack.mcmeta" // exclude from the guide repo
}
}
api {
java {
srcDir "BuildCraftAPI/api"
}
}
test {
java {
srcDir "src/test/java"
srcDir "sub_projects/expression/src/test/java"
}
}
}
if (gradle.startParameter.taskNames.contains("checkstyle")) {
checkstyle {
configFile = file("guidelines/buildcraft.checkstyle")
toolVersion = "7.2"
}
task checkstyle {}
tasks["checkstyle"].dependsOn checkstyleApi
tasks["checkstyle"].dependsOn checkstyleMain
tasks["checkstyleApi"].enabled = true
tasks["checkstyleMain"].enabled = true
tasks["checkstyleTest"].enabled = false
}
task setupSubProjects(dependsOn: "sub_projects:expression:generateSources") {
// Just an inter-dependency task
}
eclipseClasspath.dependsOn setupSubProjects
ideaModule.dependsOn setupSubProjects
compileJava.dependsOn setupSubProjects
runClient.jvmArgs += "-Dbuildcraft.dev=true"
for (String s :"-XX:+UseG1GC -Xmx2G -Xms2G -Dsun.rmi.dgc.server.gcInterval=2147483646 -XX:+UnlockExperimentalVMOptions -XX:G1NewSizePercent=20 -XX:G1ReservePercent=20 -XX:MaxGCPauseMillis=50 -XX:G1HeapRegionSize=32M".split(" ")) {
runClient.jvmArgs += s
}
// Obfuscated Jar location
ext.jarFile = zipTree(jar.archivePath)
// Add API dir to the IDEA module
idea.module.sourceDirs += sourceSets.api.java.srcDirs
processResources
{
// replace stuff in mcmod.info, nothing else
from(sourceSets.main.resources.srcDirs) {
include 'mcmod.info'
// replace version and mcversion
// ${version} and ${mcversion} are the exact strings being replaced
expand "version":project.version, "mcversion":project.minecraft.version
}
// copy everything else, that's not the mcmod.info
from(sourceSets.main.resources.srcDirs) {
exclude 'mcmod.info'
exclude 'pack.mcmeta'
exclude 'pack.png'
}
}
compileJava {
options.compilerArgs << "-Xmaxerrs" << "2000"
options.compilerArgs << "-Xmaxwarns" << "2"
options.compilerArgs << "-Xlint:all"
options.compilerArgs << "-Xdiags:verbose"
options.compilerArgs << "-encoding" << "UTF-8"
}
javadoc {
options.setUse(true)
options.addStringsOption("Xmaxerrs").setValue(["2000"])
options.addStringsOption("Xmaxwarns").setValue(["2000"])
options.addStringsOption("Xdoclint:all")
options.setEncoding("UTF-8")
}
// --------------------
// extra jar section
// -------------------
def createMCModInfo(String taskName)
{
return new File("$projectDir/build/processing/" + taskName + "/mcmod.info")
}
def writeMCModInfo(String taskName, int... ids)
{
File temp = createMCModInfo(taskName)
temp.parentFile.mkdirs()
if (temp.exists())
temp.delete()
temp.createNewFile()
def elements = []
for (int id : ids) {
elements += ext.mcModInfo[id];
}
String prettyPrinted = groovy.json.JsonOutput.prettyPrint(groovy.json.JsonOutput.toJson(elements))
prettyPrinted = prettyPrinted.replace("\$version", project.version)
prettyPrinted = prettyPrinted.replace("\${mcversion}", project.minecraft.version)
temp.write(prettyPrinted)
return temp
}
def parseConfig(File config) {
if (!config.exists())
return null
config.withReader {
def prop = new Properties()
prop.load(it)
return (new ConfigSlurper().parse(prop))
}
}
def unzippedSourceJar = new File("$projectDir/build/processing/tasks/unzipped_src_jar/unzip")
def libsDir = new File(System.getenv("LIBS_DIR") ?: "$projectDir/build/libs/", version)
def modulesDir = new File(libsDir, "modules")
def modulesDirSrc = new File(modulesDir, "src")
// forge (or gradle?) creates a special sourceJar which has been processed
// This task unzips that created jar, so that partial source jars can be created.
task unzipSourceJar(type: Copy, dependsOn: sourceJar) {
from (zipTree(sourceJar.archivePath)) {
include "**"
}
into unzippedSourceJar
}
// add api classes to javadoc
javadoc {
source += sourceSets.api.allSource
}
// add a javadoc jar
task javadocJar(type: Jar, dependsOn: javadoc) {
destinationDir = libsDir
appendix = "main"
classifier = 'javadoc'
from '$projectDir/build/docs/javadoc'
}
// because the normal output has been made to be obfuscated
task deobfJar(type: Jar) {
destinationDir = libsDir
appendix = "main"
from sourceSets.main.output
from sourceSets.api.output
classifier = 'dev'
}
task writeModInfos() {
outputs.upToDateWhen { false }
doLast {
writeMCModInfo("lib", 0)
writeMCModInfo("core", 0, 1)
writeMCModInfo("builders", 2)
writeMCModInfo("energy", 3)
writeMCModInfo("factory", 4)
writeMCModInfo("silicon", 5)
writeMCModInfo("transport", 6)
writeMCModInfo("robotics", 7)
}
}
task apiJar(type: Jar, dependsOn: [reobfJar, writeModInfos]) {
destinationDir = modulesDir
appendix = "api"
from(project.ext.jarFile) {
includes.addAll(["buildcraft/api/**"])
}
}
task apiSrcJar(type: Jar, dependsOn: [build, unzipSourceJar]) {
destinationDir = modulesDirSrc
appendix = "api"
classifier = 'sources'
from sourceSets.api.allSource
}
task libJar(type: Jar, dependsOn: [reobfJar, writeModInfos]) {
destinationDir = modulesDir
appendix = "lib"
from(createMCModInfo("lib").parentFile)
from(project.ext.jarFile) {
includes.addAll(["assets/buildcraft/**", "assets/buildcraftlib/**", "data/buildcraftlib/**", "buildcraft/lib/**", "buildcraft/api/**", "changelog/**", "LICENSE**", "versions.txt"])
}
}
task libSrcJar(type: Jar, dependsOn: [build, unzipSourceJar]) {
destinationDir = modulesDirSrc
appendix = "lib"
classifier = "sources"
from sourceSets.api.allSource
from (unzippedSourceJar) {
includes.addAll(["assets/buildcraft/**", "assets/buildcraftlib/**", "buildcraft/lib/**", "LICENSE**"])
}
}
task coreJar(type: Jar, dependsOn: [reobfJar, writeModInfos]) {
destinationDir = modulesDir
appendix = "core"
from(createMCModInfo("core").parentFile)
from(project.ext.jarFile) {
includes.addAll(["assets/buildcraft/**", "assets/buildcraftlib/**", "data/buildcraftlib/**", "assets/buildcraftcore/**", "data/buildcraftcore/**", "buildcraft/lib/**", "buildcraft/core/**", "buildcraft/api/**", "changelog/**", "LICENSE**", "versions.txt"])
}
}
for (String module : ["builders", "energy", "factory", "silicon", "transport", "robotics"]) {
task (module + "Jar", type: Jar, dependsOn: [reobfJar, writeModInfos]) {
destinationDir = modulesDir
appendix = module
from(createMCModInfo(module).parentFile)
from(project.ext.jarFile) {
includes.addAll(["assets/buildcraft$module/**", "data/buildcraft$module/**", "buildcraft/$module/**", "LICENSE"])
}
}
}
task mainJar(type: Jar, dependsOn:reobfJar) {
destinationDir = libsDir
appendix = "main"
from(project.ext.jarFile) {
includes.addAll("**")
}
}
task mainSrcJar(type: Jar, dependsOn:[reobfJar, unzipSourceJar]) {
destinationDir = libsDir
appendix = "main"
classifier = "sources"
from sourceSets.api.allSource
from (unzippedSourceJar) {
includes.add("**")
}
}
// Configure BC compat
if (rootProject != project) {
rootProject.allJar.
from (project.ext.jarFile) {
includes.addAll("**")
exclude("mcmod.info")
}
rootProject.allJar.dependsOn(mainJar)
rootProject.allSrcJar.
from (unzippedSourceJar) {
includes.add("**")
exclude("mcmod.info")
}
rootProject.allJar.dependsOn(unzipSourceJar)
}
// add api classes to main package
jar {
from sourceSets.api.output
}
// make sure all of these happen when we run build
build.dependsOn mainSrcJar, apiJar, deobfJar, javadocJar
// --------------------
// maven section
// -------------------
// create the deployerJars dependency configuration
configurations {
deployerJars
sshAntTask
}
dependencies {
// dependency in deployerJars, for maven deployment. see definition in mavenDeployer{} below
deployerJars "org.apache.maven.wagon:wagon-ssh:2.2"
sshAntTask "org.apache.ant:ant-jsch:1.9.6", "com.jcraft:jsch:0.1.53"
}
// specify artifacts to be uploaded
artifacts {
// the default jar is already here by default
archives sourceJar
archives javadocJar
// Modules
archives apiJar
archives libJar
archives coreJar
archives buildersJar
archives energyJar
archives factoryJar
archives siliconJar
archives transportJar
archives roboticsJar
archives mainJar
}
def sftp(String subPath, Closure antFileset = {}) {
ant {
taskdef(name: 'scp', classname: 'org.apache.tools.ant.taskdefs.optional.ssh.Scp',
classpath: configurations.sshAntTask.asPath)
Map sftpArgs = [
verbose : 'yes',
todir : priv.username + "@" + priv.host + ":" + priv.remotedir + version + "/" + subPath,
port: priv.port,
password: priv.password,
sftp: true,
trust: 'yes'
]
delegate.scp(sftpArgs) {
antFileset.delegate = delegate
antFileset()
}
}
}
publishing {
repositories {
maven {
url System.getenv("MAVEN_DIR") ?: "$projectDir/build/maven"
}
}
publications {
pub_apiJar(MavenPublication) {
groupId "com.mod-buildcraft"
artifactId "buildcraft-api"
version project.version
artifact apiJar
}
pub_apiSrcJar(MavenPublication) {
groupId "com.mod-buildcraft"
artifactId "buildcraft-api"
version project.version
artifact apiSrcJar
}
pub_libJar(MavenPublication) {
groupId "com.mod-buildcraft"
artifactId "buildcraft-lib"
version project.version
artifact libJar
}
pub_libSrcJar(MavenPublication) {
groupId "com.mod-buildcraft"
artifactId "buildcraft-lib"
version project.version
artifact libSrcJar
}
pub_mainJar(MavenPublication) {
groupId "com.mod-buildcraft"
artifactId "buildcraft-main"
version project.version
artifact mainJar
}
pub_mainSrcJar(MavenPublication) {
groupId "com.mod-buildcraft"
artifactId "buildcraft-main"
version project.version
artifact mainSrcJar
}
}
}
task upload(dependsOn: build) {
description = 'Update files on remote server.'
doFirst {
sftp("") {
fileset(dir: libsDir)
}
sftp("modules") {
fileset(dir: 'modules')
}
}
}
if (ext.priv == null)
upload.enabled = false
uploadArchives {
// make sure this happens after reobfuscation
//dependsOn "reobf"
repositories {
add project.repositories.mavenLocal()
}
}