forked from MovingBlocks/Terasology
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.gradle
639 lines (551 loc) · 22.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
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
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
/*
* This is a Gradle build file:
* - Gradle Homepage: http://gradle.org/
* - Gradle Documentation: http://gradle.org/documentation
* - View tasks for this project: $ gradlew tasks
*/
apply plugin: 'java'
apply plugin: 'project-report'
apply plugin: 'eclipse'
apply plugin: 'idea'
apply plugin: 'checkstyle'
/*
* Update Gradle Wrapper:
* 1. Uncomment 'wrapper' task
* 2. Change 'gradleVersion'
* 3. Run "gradlew wrapper"
* 4. Comment 'wrapper' task
*/
//task wrapper(type: Wrapper) {
// gradleVersion = '1.4'
//}
import groovy.json.JsonSlurper
import org.apache.tools.ant.filters.FixCrLfFilter;
import java.text.SimpleDateFormat;
def dateTimeFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssXXX")
dateTimeFormat.timeZone = TimeZone.getTimeZone("UTC")
// Template for building new copies of "mod.txt" (should really move to a file template)
def DEFAULT_MOD_TXT_START = '{\n "id" : "'
def DEFAULT_MOD_TXT_END = '",\n "displayName" : "",\n "author" : "",\n "description" : "",\n "dependencies" : []\n}'
def LWJGL_VERSION = '2.9.0'
// Declare "extra properties" (variables) for the project - a Gradle thing that makes them special.
ext {
// Project paths
dirApplet = 'applet'
dirNatives = 'natives'
dirSavedWorlds = 'SAVED_WORLDS'
subDirLibs = 'libs'
subDirMods = 'mods'
destDirApplet = 'distributions/applet'
destDirApplication = 'distributions/application'
destDirMainOutput = 'mainOutput'
destDirMods = "distributions/$subDirMods"
mainClassNameEditor = 'org.terasology.editor.TeraEd'
mainClassName = 'org.terasology.game.Terasology'
jarFileName = 'Terasology.jar'
// Read environment variables, including variables passed by jenkins continuous integration server
env = System.getenv()
// Stuff for our automatic version file setup
startDateTimeString = dateTimeFormat.format(new Date())
versionInfoFileDir = new File(sourceSets.main.output.resourcesDir, 'org/terasology/version')
versionInfoFile = new File(versionInfoFileDir, 'versionInfo.properties')
versionFileName = 'VERSION'
versionBase = rootProject.file("version.txt").text.trim()
displayVersion = versionBase
}
// Declare remote repositories we're interested in - library files will be fetched from here
repositories {
// Main Maven repo
mavenCentral()
// Custom repo for slick
maven {
url "http://slick2d-maven-dependencies.googlecode.com/svn/trunk/repository/"
}
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Natives //
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Define a custom configuration named "natives"
configurations {
natives
}
// For the "natives" configuration make it depend on the native files from LWJGL
dependencies {
<<<<<<< HEAD
natives group: 'org.lwjgl.lwjgl', name: 'lwjgl', version: '2.9.0'
=======
natives group: 'org.lwjgl.lwjgl', name: 'lwjgl', version: LWJGL_VERSION
>>>>>>> upstream/develop
}
task extractWindowsNatives(type:Sync) {
description = "Extracts the Windows natives from the downloaded zip"
from {
configurations.natives.collect { it.getName().contains('-natives-window') ? zipTree(it) : [] }
}
into ("$dirNatives/windows")
exclude ('META-INF/**')
}
task extractMacOSXNatives(type:Sync) {
description = "Extracts the MacOS natives from the downloaded zip"
from {
configurations.natives.collect { it.getName().contains('-natives-osx') ? zipTree(it) : [] }
}
into ("$dirNatives/macosx")
exclude ('META-INF/**')
}
task extractLinuxNatives(type:Sync) {
description = "Extracts the Linux natives from the downloaded zip"
from {
configurations.natives.collect { it.getName().contains('-natives-linux') ? zipTree(it) : [] }
}
into ("$dirNatives/linux")
exclude ('META-INF/**')
}
task extractNatives {
description = "Triggers all of the natives extraction tasks"
dependsOn extractWindowsNatives
dependsOn extractLinuxNatives
dependsOn extractMacOSXNatives
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Java Section //
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Set the expected module Java level (can use a higher Java to run, but should not use features from a higher Java)
sourceCompatibility = 1.7
// Add additional "source set" beyond the default (src/main/ + src/test/), in this case src/dev/ (utility)
sourceSets {
dev
}
// Customizations for the main compilation configuration
configurations {
// Exclude a couple JWJGL modules that aren't needed during compilation (OS specific stuff in these two perhaps)
compile {
exclude module: 'lwjgl-platform'
exclude module: 'jinput-platform'
}
// Beyond the standard compile "configuration" we declare one called "devCompile" specific to the "dev" source set
devCompile.extendsFrom compile
}
// Primary dependencies definition
dependencies {
// Main library files fetched online
compile group: 'org.codehaus.groovy', name: 'groovy', version: '1.8.7'
compile group: 'org.slf4j', name: 'slf4j-api', version: '1.7.2'
compile group: 'com.google.guava', name: 'guava', version: '13.0.1'
compile group: 'com.google.code.gson', name: 'gson', version: '2.2.2'
compile group: 'com.google.protobuf', name: 'protobuf-java', version: '2.4.1'
compile group: 'net.sf.trove4j', name: 'trove4j', version: '3.0.3'
compile group: 'com.projectdarkstar.ext.jorbis', name: 'jorbis', version: '0.0.17'
<<<<<<< HEAD
compile group: 'org.lwjgl.lwjgl', name: 'lwjgl', version: '2.9.0'
compile group: 'org.lwjgl.lwjgl', name: 'lwjgl_util', version: '2.9.0'
=======
compile group: 'org.lwjgl.lwjgl', name: 'lwjgl', version: LWJGL_VERSION
compile group: 'org.lwjgl.lwjgl', name: 'lwjgl_util', version: LWJGL_VERSION
>>>>>>> upstream/develop
compile group: 'io.netty', name: 'netty', version: '3.5.11.Final'
compile group: 'org.reflections', name: 'reflections', version: '0.9.8'
compile group: 'java3d', name: 'vecmath', version: '1.3.1'
compile group: 'com.github.jponge', name: 'lzma-java', version: '1.2'
compile group: 'org.newdawn.slick', name: 'slick', version: '236'
compile group: 'net.java.dev.jna', name: 'jna', version: '3.5.2'
compile group: 'net.java.dev.jna', name: 'platform', version: '3.5.2'
// Wildcard dependency to catch any libs provided with the project
compile fileTree(dir: 'libs', include: '*.jar')
// Needed as "compile" for logback.groovy in IntelliJ - otherwise it could be left as a runtime only dependency
//TODO: Find way to avoid compiling logback.groovy to the resource dir
compile group: 'ch.qos.logback', name: 'logback-classic', version: '1.0.13'
// These dependencies are only needed for running tests
testCompile group: 'junit', name: 'junit', version: '4.10'
testCompile group: 'org.mockito', name: 'mockito-all', version: '1.9.0'
// In addition to all the above the dev source set also needs to depend on what gets compiled in main
devCompile sourceSets.main.output
}
// Instructions for packaging a jar file for the main project
jar {
archiveName = jarFileName
manifest {
def manifestClasspath = "$subDirLibs/"+configurations.runtime.collect { it.getName() }.join(" $subDirLibs/")
attributes("Main-Class": mainClassName, "Class-Path" : manifestClasspath, "Implementation-Title": project.name, "Implementation-Version": env.BUILD_NUMBER + ", " + env.GIT_BRANCH + ", " + env.BUILD_ID + ", " + displayVersion)
}
}
task sourceJar(type: Jar) {
description = "Create a JAR with all sources (main: java, resources)"
manifest.attributes("Implementation-Title": project.name)
classifier = 'sources'
from sourceSets.main.output
}
task javadocJar(type: Jar, dependsOn: javadoc) {
description = "Create a JAR with the JavaDoc for the java sources"
manifest.attributes("Implementation-Title": project.name)
classifier = 'javadoc'
from javadoc.destinationDir
}
// Extra details provided for unit tests
test {
// ignoreFailures: Specifies whether the build should break when the verifications performed by this task fail.
ignoreFailures = true
// showStandardStreams: makes the standard streams (err and out) visible at console when running tests
testLogging.showStandardStreams = true
// Arguments to include while running tests
jvmArgs '-Xms512m', '-Xmx1024m', '-XX:MaxPermSize=128m'
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Mods section (set up as modules in IntelliJ) //
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
subprojects {
// Ignore the actual "mods" directory as Gradle will travel the project "tree" and process in-between directories
if (name != 'mods') {
// Each mod gets set up as Java and prepped for either Eclipse or IntelliJ
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'idea'
// Change the output dir for each mod
sourceSets {
main {
java {
output.classesDir 'classes'
}
}
}
// Generate all the valid sub directories
task createSkeleton() {
mkdir('assets')
mkdir('src/main/java')
mkdir('assets/animations')
mkdir('assets/blocks')
mkdir('assets/blockTiles')
mkdir('assets/fonts')
mkdir('assets/materials')
mkdir('assets/mesh')
mkdir('assets/music')
mkdir('assets/prefabs')
mkdir('assets/shaders')
mkdir('assets/shapes')
mkdir('assets/skeletalMesh')
mkdir('assets/sounds')
mkdir('assets/textures')
mkdir('src/test/java')
}
// Keep everything in the "assets" dir in sync with the compiled output (since they're already "ready")
task syncAssets(type: Sync) {
from 'assets'
into 'classes/assets'
}
// Deal with the mod info file and if one doesn't exist make a new one
def modFile = file('mod.txt')
if (!modFile.exists()) {
modFile.createNewFile()
modFile.withWriter { writer ->
writer.write(DEFAULT_MOD_TXT_START)
writer.write(name)
writer.write(DEFAULT_MOD_TXT_END)
}
}
// Put the info file into the output
jar.doFirst {
copy {
from 'mod.txt'
into 'classes'
}
}
// Jarring up modules should include the assets
jar.dependsOn syncAssets
// Go parse out any dependencies defined in the mod info file, we'll need those later
def slurper = new JsonSlurper()
def modConfig = slurper.parseText( file('mod.txt').text)
def modDepends = modConfig.dependencies;
// Prep an IntelliJ module for the mod
idea {
module {
// Change around the output specific to the mod a bit
inheritOutputDirs = false
outputDir = file('classes')
testOutputDir = file('testClasses')
// Generate the project config in a .idea dir rather than as a .iml file
iml {
generateTo = file('.idea')
}
}
}
// For Eclipse just make sure the classpath is right
eclipse {
classpath {
defaultOutputDir = file('classes')
}
}
// Same repo config per module as parent project (maybe there's a way to simply inherit?
repositories {
mavenCentral()
maven {
url "http://slick2d-maven-dependencies.googlecode.com/svn/trunk/repository/"
}
}
// Set dependencies, note how the parsed dependencies from the mod info file are included here
dependencies {
compile project(':')
testCompile group: 'junit', name: 'junit', version: '4.10'
for (dependency in modDepends) {
compile project(':mods:' + dependency)
}
}
}
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Checkstyle settings //
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
checkstyle.ignoreFailures = true
checkstyle.configProperties.samedir = checkstyle.configFile.parentFile
/* Optional check plugins
apply plugin: 'codenarc'
apply plugin: 'findbugs'
apply plugin: 'pmd'
// ignoreFailures: Whether or not this task will ignore failures and continue running the build.
codenarc.ignoreFailures = true
findbugs.ignoreFailures = true
pmd.ignoreFailures = true
*/
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Miscellaneous //
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
task assembleMainOutput(type:Sync) {
description = "Helper task for when we're trying to run the game from the command line or via TeraEd"
from sourceSets.main.output
into "$buildDir/$destDirMainOutput"
}
task modClasses {
description = "Another helper task for when we're trying to run the game from the command line or via TeraEd"
subprojects.each { project ->
if (project.name != 'mods') {
modClasses.dependsOn project.tasks['classes']
}
}
}
task run(type:JavaExec) {
description = "Run 'Terasology' to play the game"
dependsOn extractNatives
dependsOn assembleMainOutput
dependsOn modClasses
main = mainClassName
classpath "$buildDir/$destDirMainOutput"
classpath configurations.runtime
}
task runTeraEd(type:JavaExec) {
description = "Run 'TeraEd' to customize shader settings while the game is running"
dependsOn extractNatives
dependsOn assembleMainOutput
dependsOn modClasses
main = mainClassNameEditor
classpath "$buildDir/$destDirMainOutput"
classpath configurations.runtime
}
task deleteSavedWorldsSubfolders(type: Delete) {
description = "Delete all subfolders from '$dirSavedWorlds'"
delete file(dirSavedWorlds).listFiles().findAll { it.directory }
}
task deleteSavedWorldsFiles(type: Delete) {
description = "Delete all files from '$dirSavedWorlds'"
delete file(dirSavedWorlds).listFiles().findAll { !it.directory }
}
task zipSavedWorldsFolder(type: Zip) {
description = "Creates a SavedWorlds ZIP file from '$dirSavedWorlds'"
appendix = "SavedWorlds"
classifier = startDateTimeString
into (dirSavedWorlds) {
from dirSavedWorlds
}
}
task runProtobufWindows(type:Exec) {
description = "Run 'Protobuf Compiler' (Windows)"
commandLine 'protobuf\\compiler\\protoc.exe', '--proto_path=src\\main\\protobuf', '--java_out', 'src\\main\\java', 'src\\main\\protobuf\\*'
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Version file stuff //
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
task createVersionInfoFile {
inputs.property('dateTime', startDateTimeString)
onlyIf { env.BUILD_URL != null }
doLast {
versionInfoFileDir.mkdirs()
ant.propertyfile (file: versionInfoFile) {
ant.entry(key:'buildNumber',value:env.BUILD_NUMBER)
ant.entry(key:'buildId',value:env.BUILD_ID)
ant.entry(key:'buildTag',value:env.BUILD_TAG)
ant.entry(key:'buildUrl',value:env.BUILD_URL)
ant.entry(key:'jobName',value:env.JOB_NAME)
ant.entry(key:'gitBranch',value:env.GIT_BRANCH)
ant.entry(key:'gitCommit',value:env.GIT_COMMIT)
ant.entry(key:'dateTime',value:startDateTimeString)
ant.entry(key:'displayVersion',value:displayVersion)
}
}
}
createVersionInfoFile.dependsOn processResources
jar.dependsOn createVersionInfoFile
task createVersionFile(type: Copy) {
inputs.property('dateTime', startDateTimeString)
onlyIf { env.BUILD_URL != null }
from 'src/template'
into "$buildDir"
include versionFileName
expand(buildNumber: env.BUILD_NUMBER, buildUrl: env.BUILD_URL, gitBranch: env.GIT_BRANCH, dateTime: startDateTimeString, displayVersion: displayVersion)
filter(FixCrLfFilter, eol:FixCrLfFilter.CrLf.newInstance("crlf"))
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Distributions (prepared artifacts) //
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
task modAssemble {
description = "Assembles the mods"
subprojects.each { project ->
if (project.name != 'mods') {
modAssemble.dependsOn project.tasks['assemble']
}
}
}
task distMods {
description = "Distributes the mods"
dependsOn modAssemble
subprojects.each { project ->
if (project.name != 'mods') {
project.task('dist', type: Copy) {
from (project.libsDir)
into "$buildDir/$destDirMods"
}
distMods.dependsOn project.tasks['dist']
}
}
}
task distApplication(type:Sync) {
description = "Creates an Application folder"
dependsOn extractNatives
dependsOn distMods
into("$buildDir/$destDirApplication")
from ('Heightmap.txt') {}
from ('README.markdown') {
filter(FixCrLfFilter, eol:FixCrLfFilter.CrLf.newInstance("crlf"))
rename('README.markdown', 'README')
}
from ('LICENSE') {
filter(FixCrLfFilter, eol:FixCrLfFilter.CrLf.newInstance("crlf"))
}
from ('NOTICE') {
filter(FixCrLfFilter, eol:FixCrLfFilter.CrLf.newInstance("crlf"))
}
from jar
from('launchScripts') {
exclude('Launcher.xml')
exclude('LauncherTeraEd.xml')
}
into(subDirLibs) {
from configurations.runtime
}
into(dirNatives) {
from dirNatives
}
into(subDirMods) {
from "$buildDir/$destDirMods"
}
}
// Make a configuration specific to applet stuff
configurations {
applet
}
// Applet needs the LWJGL applet dependency
dependencies {
<<<<<<< HEAD
applet group: 'org.lwjgl.lwjgl', name: 'lwjgl_util_applet', version: '2.9.0'
=======
applet group: 'org.lwjgl.lwjgl', name: 'lwjgl_util_applet', version: LWJGL_VERSION
>>>>>>> upstream/develop
}
task distApplet(type:Sync) {
description = "Creates an Applet folder"
dependsOn distMods
into("$buildDir/$destDirApplet")
from ('README.markdown') {
filter(FixCrLfFilter, eol:FixCrLfFilter.CrLf.newInstance("crlf"))
rename('README.markdown', 'README')
}
from ('LICENSE') {
filter(FixCrLfFilter, eol:FixCrLfFilter.CrLf.newInstance("crlf"))
}
from ('NOTICE') {
filter(FixCrLfFilter, eol:FixCrLfFilter.CrLf.newInstance("crlf"))
}
from jar
from(dirApplet) {
exclude '*.keystore'
}
from configurations.applet
into(subDirLibs) {
from configurations.runtime
from configurations.natives
}
into(subDirMods) {
from "$buildDir/$destDirMods"
}
}
// At the end of the applet distribution sign the jar files so they can get expanded rights in a browser
distApplet.doLast {
file("$buildDir/$destDirApplet").listFiles().each {
if (it.getName().endsWith(".jar"))
ant.signjar(jar: it, keystore: "$dirApplet/tera.keystore", alias: 'Terasology', storepass: 'Terasology')
}
file("$buildDir/$destDirApplet/$subDirLibs").listFiles().each {
if (it.getName().endsWith(".jar"))
ant.signjar(jar: it, keystore: "$dirApplet/tera.keystore", alias: 'Terasology', storepass: 'Terasology')
}
file("$buildDir/$destDirApplet/$subDirMods").listFiles().each {
if (it.getName().endsWith(".jar"))
ant.signjar(jar: it, keystore: "$dirApplet/tera.keystore", alias: 'Terasology', storepass: 'Terasology')
}
}
task distModsZip(type:Zip) {
description = "Creates a MODs ZIP file from '$buildDir/$destDirMods'"
dependsOn distMods
appendix 'Mods'
from "$buildDir/$destDirMods"
}
task distApplicationZip(type:Zip) {
description = "Creates an Application ZIP file from '$buildDir/$destDirApplication'"
dependsOn distApplication
dependsOn createVersionInfoFile
dependsOn createVersionFile
//appendix 'Application'
from "$buildDir/$destDirApplication"
from "$buildDir/$versionFileName"
}
task distAppletZip(type:Zip) {
description = "Creates an Applet ZIP file from '$buildDir/$destDirApplet'"
dependsOn distApplet
dependsOn createVersionInfoFile
dependsOn createVersionFile
appendix 'Applet'
from "$buildDir/$destDirApplet"
from "$buildDir/$versionFileName"
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// General IDE customization //
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Make sure the IDE prep includes extraction of natives
ideaModule.dependsOn extractNatives
eclipseClasspath.dependsOn extractNatives
// For IntelliJ add a bunch of excluded directories
idea {
// Add development "dev" dir
module.sourceDirs += sourceSets.dev.allJava.srcDirs
// Exclude Gradle dir
module.excludeDirs += file('gradle')
// Exclude Eclipse dirs
module.excludeDirs += file('bin')
module.excludeDirs += file('.settings')
// Exclude special dirs
module.excludeDirs += file('natives')
module.excludeDirs += file('protobuf')
// Exclude output dirs
module.excludeDirs += file('logs')
module.excludeDirs += file('SAVED_WORLDS')
module.excludeDirs += file('worlds')
module.excludeDirs += file('screens')
module.excludeDirs += file('screenshots')
}