forked from MovingBlocks/Terasology
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.gradle
273 lines (217 loc) · 11.8 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
// The engine build is the primary Java project and has the primary list of dependencies
// Grab all the common stuff like plugins to use, artifact repositories, code analysis config, etc
apply from: "$rootDir/config/gradle/artifactory.gradle"
import groovy.json.JsonSlurper
import org.reflections.Reflections;
import org.reflections.scanners.SubTypesScanner;
import org.reflections.scanners.TypeAnnotationsScanner;
import java.text.SimpleDateFormat;
def dateTimeFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssXXX")
dateTimeFormat.timeZone = TimeZone.getTimeZone("UTC")
// Declare "extra properties" (variables) for the project - a Gradle thing that makes them special.
ext {
// Read environment variables, including variables passed by jenkins continuous integration server
env = System.getenv()
templatesDir = new File(rootDir, 'templates')
// Stuff for our automatic version file setup
startDateTimeString = dateTimeFormat.format(new Date())
versionInfoFileDir = new File(buildDir, 'classes/org/terasology/version')
versionInfoFile = new File(versionInfoFileDir, 'versionInfo.properties')
versionFileName = 'VERSION'
versionBase = new File(templatesDir, "version.txt").text.trim()
displayVersion = versionBase
}
def convertGitBranch = { gitBranch ->
if (gitBranch != null) {
// Remove "origin/" from "origin/develop"
gitBranch.substring(gitBranch.lastIndexOf("/") + 1)
} else {
""
}
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Java Section //
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Engine for now has two source sets
sourceSets {
// Main is almost everything - the true engine
main {
java {
output.classesDir 'build/classes'
}
// This makes the resources (assets, 3d wizardry includes, etc) also go to build/classes
output.resourcesDir 'build/classes'
}
// Dev contains some utilities. Not really sure this needs to be included with the build? But hey. Dump it in
dev {
java {
output.classesDir 'build/classes'
}
}
}
// 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
}
// TODO: Remove when we don't need to rely on snapshots. Wonder why modules respected this set in root project, engine not so much
configurations.all {
resolutionStrategy.cacheChangingModulesFor 0, 'seconds'
}
// Primary dependencies definition
dependencies {
// Storage and networking
compile group: 'com.google.guava', name: 'guava', version: '23.0'
compile group: 'com.google.code.gson', name: 'gson', version: '2.6.2'
compile group: 'com.google.protobuf', name: 'protobuf-java', version: '2.6.1'
compile group: 'net.sf.trove4j', name: 'trove4j', version: '3.0.3'
compile group: 'io.netty', name: 'netty', version: '3.10.5.Final'
// Java magic
compile group: 'net.java.dev.jna', name: 'jna-platform', version: '4.2.2'
compile group: 'org.reflections', name: 'reflections', version: '0.9.10'
compile group: 'org.javassist', name: 'javassist', version: '3.20.0-GA'
compile group: 'com.esotericsoftware', name: 'reflectasm', version: '1.11.1'
// Graphics, 3D, UI, etc
compile group: 'org.lwjgl.lwjgl', name: 'lwjgl', version: LwjglVersion
compile group: 'org.lwjgl.lwjgl', name: 'lwjgl_util', version: LwjglVersion
compile group: 'java3d', name: 'vecmath', version: '1.3.1' // Note: Downgraded to this release until TeraMath ready
compile "org.joml:joml:1.8.1"
compile group: 'org.abego.treelayout', name: 'org.abego.treelayout.core', version: '1.0.3'
compile group: 'com.miglayout', name: 'miglayout-core', version: '5.0'
compile group: 'de.matthiasmann.twl', name: 'PNGDecoder', version: '1111'
// Assembly & Bytecode
compile group: 'org.ow2.asm', name: 'asm', version: '5.0.3'
compile group: 'org.ow2.asm', name: 'asm-tree', version: '5.0.4'
compile group: 'org.ow2.asm', name: 'asm-util', version: '5.0.4'
compile group: 'org.ow2.asm', name: 'asm-commons', version: '5.0.4'
// Logging and audio
compile group: 'org.slf4j', name: 'slf4j-api', version: '1.7.21'
compile group: 'com.projectdarkstar.ext.jorbis', name: 'jorbis', version: '0.0.17'
// Small-time 3rd party libs we've stored in our Artifactory for access
compile group: 'ec.util', name: 'MersenneTwister', version: '20'
compile group: 'org.eaxy', name: 'eaxy', version: '0.1'
// telemetry
compile (group: 'com.snowplowanalytics', name: 'snowplow-java-tracker', version :'0.8.0'){
exclude group:'org.slf4j',module:'slf4j-simple'
}
compile group: 'net.logstash.logback', name: 'logstash-logback-encoder', version: '4.10'
// Discord RPC
compile 'com.jagrosh:DiscordIPC:0.4'
// Our developed libs
compile group: 'org.terasology', name: 'gestalt-module', version: '5.1.4'
compile group: 'org.terasology', name: 'gestalt-asset-core', version: '5.1.4'
compile group: 'org.terasology', name: 'TeraMath', version: '1.4.0'
compile group: 'org.terasology.bullet', name: 'tera-bullet', version: '1.3.1'
compile group: 'org.terasology', name: 'splash-screen', version: '1.0.2'
compile group: 'org.terasology.jnlua', name: 'JNLua', version: '0.1.0-SNAPSHOT'
// Wildcard dependency to catch any libs provided with the project (remote repo preferred instead)
compile fileTree(dir: 'libs', include: '*.jar')
compile group: 'ch.qos.logback', name: 'logback-classic', version: '1.2.3'
runtime group: 'org.slf4j', name: 'jul-to-slf4j', version: '1.7.21'
// In addition to all the above the dev source set also needs to depend on what gets compiled in main
devCompile sourceSets.main.output
// Dependency on CrashReporter, conditionally either from source or via binary
// TODO: Consider moving this back to the PC Facade instead of having the engine rely on it?
File wouldBeSrcPath = new File(rootDir, 'libs/CrashReporter')
println "ENGINE Scanning for source CrashReporter at: " + wouldBeSrcPath.getAbsolutePath()
if (wouldBeSrcPath.exists()) {
println "*** Identified CrashReporter source, using that"
//compile ':libs:CrashReporter:cr-terasology'
def targetProject = findProject(':libs:CrashReporter:cr-terasology')
println "Found the project? " + targetProject
//compile targetProject
compile project(':libs:CrashReporter:cr-terasology')
} else {
println "*** Setting a CrashReporter binary dependency, not present as source"
compile group: 'org.terasology.crashreporter', name: 'cr-terasology', version: '4.1.0'
}
}
// Instructions for packaging a jar file for the engine
jar {
// Unlike the content modules Gradle grabs the assets as they're in a resources directory. Need to avoid dupes tho
duplicatesStrategy = 'exclude'
manifest {
def manifestClasspath = "$subDirLibs/"+configurations.runtime.collect { it.getName() }.join(" $subDirLibs/")
attributes("Class-Path" : manifestClasspath, "Implementation-Title": "Terasology-" + project.name, "Implementation-Version": env.BUILD_NUMBER + ", " + convertGitBranch(env.GIT_BRANCH) + ", " + env.BUILD_ID + ", " + displayVersion)
}
}
task cacheReflections {
description = 'Caches reflection output to make regular startup faster. May go stale and need cleanup at times.'
inputs.files project.classes.outputs.files
dependsOn classes
doLast {
// Without the .mkdirs() we might hit a scenario where the classes dir doesn't exist yet
file(sourceSets.main.output.classesDir.toString()).mkdirs()
Reflections reflections = new org.reflections.Reflections(new org.reflections.util.ConfigurationBuilder()
.addUrls(configurations.compile.collect { it.toURI().toURL()} + sourceSets.main.output.classesDir.toURI().toURL())
.setScanners(new TypeAnnotationsScanner(), new SubTypesScanner()))
reflections.save(sourceSets.main.output.classesDir.toString() + "/reflections.cache")
}
}
task cleanReflections(type: Delete) {
description = 'Cleans the reflection cache. Useful in cases where it has gone stale and needs regeneration.'
delete sourceSets.main.output.classesDir.toString() + "/reflections.cache"
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Version file stuff //
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// First read the internal version out of the engine's engine-module.txt
def moduleFile = file('src/main/resources/engine-module.txt')
if (!moduleFile.exists()) {
println "Failed to find engine-module.txt for engine"
throw new GradleException("Failed to find engine-module.txt for engine")
}
println "Scanning for version in engine-module.txt for engine"
def slurper = new JsonSlurper()
def moduleConfig = slurper.parseText(moduleFile.text)
// Gradle uses the magic version variable when creating the jar name (unless explicitly set differently)
version = moduleConfig.version
// Jenkins-Artifactory integration catches on to this as part of the Maven-type descriptor
group = 'org.terasology.engine'
println "Version for $project.name loaded as $version for group $group"
// This version info file actually goes inside the built jar and can be used at runtime
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:convertGitBranch(env.GIT_BRANCH))
ant.entry(key:'gitCommit',value:env.GIT_COMMIT)
ant.entry(key:'dateTime',value:startDateTimeString)
ant.entry(key:'displayVersion',value:displayVersion)
ant.entry(key:'engineVersion',value:version)
}
}
}
jar.dependsOn createVersionInfoFile
jar.dependsOn cacheReflections
jar.finalizedBy cleanReflections
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// General IDE customization //
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
idea {
module {
// Add development "dev" dir
sourceDirs += sourceSets.dev.allJava.srcDirs
// Change around the output a bit
inheritOutputDirs = false
outputDir = file('build/classes')
testOutputDir = file('build/testClasses')
downloadSources = true
}
}
// Make sure our config file for code analytics get extracted (vulnerability: non-IDE execution of single analytic)
ideaModule.dependsOn rootProject.extractConfig
tasks.eclipse.dependsOn rootProject.extractConfig
check.dependsOn rootProject.extractConfig