-
Notifications
You must be signed in to change notification settings - Fork 1.3k
/
build.gradle
277 lines (223 loc) · 12.3 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
// Copyright 2020 The Terasology Foundation
// SPDX-License-Identifier: Apache-2.0
// The engine build is the primary Java project and has the primary list of dependencies
plugins {
id "java-library"
}
// Grab all the common stuff like plugins to use, artifact repositories, code analysis config, etc
apply from: "$rootDir/config/gradle/publish.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 //
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
sourceSets {
main.java {
// dev/ holds things that are neither unit tests nor application code.
// For notes about whether it should be its own source set, see
// see https://github.com/MovingBlocks/Terasology/pull/4021
srcDir("src/dev/java")
}
// Adjust output path (changed with the Gradle 6 upgrade, this puts it back)
main.java.outputDir = new File("$buildDir/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)
implementation {
exclude module: 'lwjgl-platform'
exclude module: 'jinput-platform'
}
}
// 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 {
// white list packages {@see ExternalApiWhiteList class} should use `api` config
// Storage and networking
api group: 'com.google.guava', name: 'guava', version: '23.0'
api group: 'com.google.code.gson', name: 'gson', version: '2.6.2'
api group: 'net.sf.trove4j', name: 'trove4j', version: '3.0.3'
implementation group: 'io.netty', name: 'netty', version: '3.10.5.Final'
implementation group: 'com.google.protobuf', name: 'protobuf-java', version: '2.6.1'
implementation group: 'org.apache.httpcomponents', name: 'httpclient', version: '4.5.2'
// Javax for protobuf due to @Generated - needed on Java 9 or newer Javas
// TODO: Can likely replace with protobuf Gradle task and omit the generated source files instead
implementation group: 'javax.annotation', name: 'javax.annotation-api', version: '1.3.2'
//Utilities
api group: 'org.codehaus.plexus', name: 'plexus-utils', version: '1.5.6'
// Java magic
implementation group: 'net.java.dev.jna', name: 'jna-platform', version: '4.2.2'
implementation group: 'org.reflections', name: 'reflections', version: '0.9.10'
implementation group: 'org.javassist', name: 'javassist', version: '3.20.0-GA'
implementation group: 'com.esotericsoftware', name: 'reflectasm', version: '1.11.1'
// Graphics, 3D, UI, etc
api group: 'org.lwjgl.lwjgl', name: 'lwjgl', version: LwjglVersion
api group: 'org.lwjgl.lwjgl', name: 'lwjgl_util', version: LwjglVersion
api group: 'java3d', name: 'vecmath', version: '1.3.1'
api group: 'org.joml', name: 'joml', version: '1.9.25'
implementation group: 'org.abego.treelayout', name: 'org.abego.treelayout.core', version: '1.0.3'
api group: 'com.miglayout', name: 'miglayout-core', version: '5.0'
implementation group: 'de.matthiasmann.twl', name: 'PNGDecoder', version: '1111'
// Assembly & Bytecode
implementation group: 'org.ow2.asm', name: 'asm', version: '5.0.3'
implementation group: 'org.ow2.asm', name: 'asm-tree', version: '5.0.4'
implementation group: 'org.ow2.asm', name: 'asm-util', version: '5.0.4'
implementation group: 'org.ow2.asm', name: 'asm-commons', version: '5.0.4'
// Logging and audio
implementation group: 'org.slf4j', name: 'slf4j-api', version: '1.7.21'
implementation group: 'com.projectdarkstar.ext.jorbis', name: 'jorbis', version: '0.0.17'
// Small-time 3rd party libs we've stored in our Artifactory for access
implementation group: 'ec.util', name: 'MersenneTwister', version: '20'
implementation group: 'org.eaxy', name: 'eaxy', version: '0.1'
// telemetry
implementation(group: 'com.snowplowanalytics', name: 'snowplow-java-tracker', version: '0.9.0') {
exclude group: 'org.slf4j', module: 'slf4j-simple'
}
implementation group: 'net.logstash.logback', name: 'logstash-logback-encoder', version: '4.10'
// Discord RPC
api 'com.jagrosh:DiscordIPC:0.4'
// Our developed libs
api group: 'org.terasology', name: 'gestalt-module', version: '5.1.5'
api group: 'org.terasology', name: 'gestalt-util', version: '5.1.5'
api group: 'org.terasology', name: 'gestalt-asset-core', version: '5.1.5'
api group: 'org.terasology', name: 'TeraMath', version: '1.5.0'
api group: 'org.terasology.bullet', name: 'tera-bullet', version: '1.3.1'
api group: 'org.terasology', name: 'splash-screen', version: '1.0.2'
api group: 'org.terasology.jnlua', name: 'JNLua', version: '0.1.0-SNAPSHOT'
api group: 'org.terasology.nui', name: 'nui', version: '1.1.0'
api group: 'org.terasology.nui', name: 'nui-reflect', version: '1.1.0'
// Wildcard dependency to catch any libs provided with the project (remote repo preferred instead)
api fileTree(dir: 'libs', include: '*.jar')
implementation group: 'ch.qos.logback', name: 'logback-classic', version: '1.2.3'
runtimeOnly group: 'org.slf4j', name: 'jul-to-slf4j', version: '1.7.21'
// TODO: Consider moving this back to the PC Facade instead of having the engine rely on it?
implementation group: 'org.terasology.crashreporter', name: 'cr-terasology', version: '4.1.0'
}
task cacheReflections {
description = 'Caches reflection output to make regular startup faster. May go stale and need cleanup at times.'
inputs.files sourceSets.main.output.classesDirs,
// getClassesDir from all sourceSets (for any jvm (seems) language)
configurations."${sourceSets.main.runtimeClasspathConfigurationName}"
outputs.upToDateWhen(classes.outputs.upToDateSpec)
outputs.file("$buildDir/resources/main/reflections.cache")
dependsOn classes
doLast {
// Without the .mkdirs() we might hit a scenario where the classes dir doesn't exist yet
Reflections reflections = new org.reflections.Reflections(new org.reflections.util.ConfigurationBuilder()
.addUrls(inputs.files.collect { it.toURI().toURL() })
.setScanners(new TypeAnnotationsScanner(), new SubTypesScanner()))
reflections.save("$buildDir/classes/reflections.cache")
}
}
// 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"
from(tasks.getByName("cacheReflections").outputs)
manifest {
def manifestClasspath = "$subDirLibs/" + configurations."${sourceSets.main.runtimeClasspathConfigurationName}".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 cleanReflections(type: Delete) {
description = 'Cleans the reflection cache. Useful in cases where it has gone stale and needs regeneration.'
delete cacheReflections.outputs.files
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// 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
// The only case in which we make non-snapshots is when BRANCH_NAME exists and contains "master" - otherwise snapshots
if (env.BRANCH_NAME == null || !env.BRANCH_NAME.equals("master")) {
version += "-SNAPSHOT"
}
// 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)
}
}
}
//TODO: Remove it when gestalt will can to handle ProtectionDomain without classes (Resources)
task copyResourcesToClasses(type:Copy) {
from sourceSets.main.output.resourcesDir
into sourceSets.main.output.classesDirs.first()
dependsOn processResources
mustRunAfter compileJava
classes.dependsOn copyResourcesToClasses
}
jar.dependsOn createVersionInfoFile
jar.dependsOn cacheReflections
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// General IDE customization //
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
idea {
module {
// 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