forked from MovingBlocks/Terasology
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.gradle
376 lines (305 loc) · 14.2 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
// Copyright 2020 The Terasology Foundation
// SPDX-License-Identifier: Apache-2.0
// Dependencies needed for what our Gradle scripts themselves use. It cannot be included via an external Gradle file :-(
buildscript {
repositories {
// External libs - jcenter is Bintray and is supposed to be a superset of Maven Central, but do both just in case
jcenter()
mavenCentral()
gradlePluginPortal()
}
dependencies {
// Needed for caching reflected data during builds
classpath 'org.reflections:reflections:0.9.10'
classpath 'dom4j:dom4j:1.6.1'
//Spotbugs
classpath "gradle.plugin.com.github.spotbugs.snom:spotbugs-gradle-plugin:4.0.0"
// SonarQube / Cloud scanning
classpath "org.sonarsource.scanner.gradle:sonarqube-gradle-plugin:2.8"
}
}
plugins {
// Needed for extending the "clean" task to also delete custom stuff defined here like natives
id "base"
// needs for native platform("org.lwjgl") handling.
id "java-platform"
// The root project should not be an eclipse project. It keeps eclipse (4.2) from finding the sub-projects.
//apply plugin: 'eclipse'
id "idea"
// For the "Build and run using: Intellij IDEA | Gradle" switch
id "org.jetbrains.gradle.plugin.idea-ext" version "0.7"
}
import org.jetbrains.gradle.ext.ActionDelegationConfig
import java.nio.file.Files
import java.nio.file.Path
import java.nio.file.StandardCopyOption
// Test for right version of Java in use for running this script
assert org.gradle.api.JavaVersion.current().isJava8Compatible()
import org.gradle.internal.logging.text.StyledTextOutputFactory
import static org.gradle.internal.logging.text.StyledTextOutput.Style
// Check for Java 8
if(!(JavaVersion.current() == JavaVersion.VERSION_1_8 || JavaVersion.current() == JavaVersion.VERSION_11)) {
def out = services.get(StyledTextOutputFactory).create("an-ouput")
out.withStyle(Style.FailureHeader).println("WARNING: Compiling with a JDK not 8 nor 11. While some other Javas may be safe to use any newer than 11 may cause issues. If you encounter oddities try Java 8 or 11. See https://github.com/MovingBlocks/Terasology/issues/3976. Current detected Java version is ${JavaVersion.current()} from vendor ${System.getProperty("java.vendor")} located at ${System.getProperty("java.home")}")
}
// Declare "extra properties" (variables) for the project (and subs) - a Gradle thing that makes them special.
ext {
dirNatives = 'natives'
dirConfigMetrics = 'config/metrics'
templatesDir = 'templates'
// Lib dir for use in manifest entries etc (like in :engine). A separate "libsDir" exists, auto-created by Gradle
subDirLibs = 'libs'
LwjglVersion = '3.2.3'
}
// Declare remote repositories we're interested in - library files will be fetched from here
repositories {
// External libs - jcenter is Bintray and is supposed to be a superset of Maven Central, but do both just in case
jcenter()
mavenCentral()
mavenLocal()
// MovingBlocks Artifactory instance for libs not readily available elsewhere plus our own libs
maven {
name "Terasology Artifactory"
url "http://artifactory.terasology.org/artifactory/virtual-repo-live"
allowInsecureProtocol true // 😱
}
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Natives - Handles pulling in and extracting native libraries for LWJGL //
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Define configurations for natives and config
configurations {
natives
codeMetrics
}
dependencies {
// For the "natives" configuration make it depend on the native files from LWJGL
natives platform("org.lwjgl:lwjgl-bom:$LwjglVersion")
["natives-linux","natives-windows","natives-macos"].forEach {
natives "org.lwjgl:lwjgl::$it"
natives "org.lwjgl:lwjgl-assimp::$it"
natives "org.lwjgl:lwjgl-glfw::$it"
natives "org.lwjgl:lwjgl-openal::$it"
natives "org.lwjgl:lwjgl-opengl::$it"
natives "org.lwjgl:lwjgl-stb::$it"
}
// Config for our code analytics lives in a centralized repo: https://github.com/MovingBlocks/TeraConfig
codeMetrics group: 'org.terasology.config', name: 'codemetrics', version: '1.3.2', ext: 'zip'
// Natives for JNLua (Kallisti, KComputers)
natives group: 'org.terasology.jnlua', name: 'jnlua_natives', version: '0.1.0-SNAPSHOT', ext: 'zip'
// Natives for JNBullet
natives group: 'org.terasology.jnbullet', name: 'JNBullet', version: '1.0.2', ext: 'zip'
}
task extractWindowsNatives(type: Copy) {
description = "Extracts the Windows natives from the downloaded zip"
from {
configurations.natives.collect { it.getName().contains('natives-windows') ? zipTree(it) : [] }
}
into("$dirNatives/windows")
exclude('META-INF/**')
}
task extractMacOSXNatives(type: Copy) {
description = "Extracts the OSX natives from the downloaded zip"
from {
configurations.natives.collect { it.getName().contains('natives-macos') ? zipTree(it) : [] }
}
into("$dirNatives/macosx")
exclude('META-INF/**')
}
task extractLinuxNatives(type: Copy) {
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 extractJNLuaNatives(type: Copy) {
description = "Extracts the JNLua natives from the downloaded zip"
from {
configurations.natives.collect { it.getName().contains('jnlua') ? zipTree(it) : [] }
}
into("$dirNatives")
}
task extractNativeBulletNatives(type:Copy) {
description = "Extracts the JNBullet natives from the downloaded zip"
from {
configurations.natives.collect { it.getName().contains('JNBullet') ? zipTree(it) : [] }
}
into ("$dirNatives")
}
task extractNatives {
description = "Extracts all the native lwjgl libraries from the downloaded zip"
dependsOn extractWindowsNatives
dependsOn extractLinuxNatives
dependsOn extractMacOSXNatives
dependsOn extractJNLuaNatives
dependsOn extractNativeBulletNatives
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Helper tasks //
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
task extractConfig(type: Copy) {
description = "Extracts our configuration files from the zip we fetched as a dependency"
from {
configurations.codeMetrics.collect {
zipTree(it)
}
}
into "$rootDir/$dirConfigMetrics"
}
// Helper that returns a list of all local Terasology module projects
def terasologyModules() {
subprojects.findAll { it.parent.name == 'modules' }
}
// Helpers that do magic things after having dependencies attached below
task moduleClasses
task moduleJars
// This magically makes everything work - without this the desired module projects returned have no tasks :-(
gradle.projectsEvaluated {
// Note how "classes" may indirectly trigger "jar" for module dependencies of modules (module compile dependency)
moduleClasses.dependsOn(terasologyModules().classes)
// This makes it work for a full jar task
moduleJars.dependsOn(terasologyModules().jar)
}
// This is a TEMPORARY tweak to make "changing" dependencies always ('0') check for newer snapshots available
// TODO: Remove this when versioning and promotion works fully, then we shouldn't care about snapshots normally anyway
configurations.all {
resolutionStrategy.cacheChangingModulesFor 0, 'seconds'
}
// Include deletion of extracted natives in the global clean task. Without the doLast it runs on *every* execution ...
clean.doLast {
new File(dirNatives).deleteDir()
new File(dirConfigMetrics).deleteDir()
println "Cleaned root - don't forget to re-extract stuff! 'gradlew extractNatives extractConfig' will do so"
}
task protobufCompileWindows(type: Exec) {
description = "Run 'Protobuf Compiler' (Windows)"
commandLine 'protobuf\\compiler\\protoc.exe', '--proto_path=engine\\src\\main\\protobuf', '--java_out', 'engine\\src\\main\\java', 'engine\\src\\main\\protobuf\\*'
}
task protobufCompileLinux(type: Exec) {
description = "Run 'Protobuf Compiler' (Linux)"
commandLine 'protobuf/compiler/protoc', '--proto_path=engine/src/main/protobuf', '--java_out', 'engine/src/main/java', "engine/src/main/protobuf/EntityData.proto", "engine/src/main/protobuf/NetMessage.proto"
}
// Magic for replace remote dependency on local project (source)
// for Engine
allprojects {
configurations.all {
resolutionStrategy.dependencySubstitution {
substitute module("org.terasology.engine:engine") because "we have sources!" with project(":engine")
substitute module("org.terasology.engine:engine-tests") because "we have sources!" with project(":engine-tests")
}
}
}
// Magic for replace remote dependency on local project (source)
// For exists modules
project(":modules").subprojects.forEach { proj ->
project(":modules").subprojects {
configurations.all {
resolutionStrategy.dependencySubstitution {
substitute module("org.terasology.modules:${proj.name}") because "we have sources!" with project(":modules:${proj.name}")
}
}
}
}
/**
* Gathering remote modules files from remoteRepo to 'modules' for autoloading in game-time (tasks server, game etc)
*/
class RemoteModuleGatherer implements DependencyResolutionListener {
private final Path modulesDir
private final Logger logger
RemoteModuleGatherer(Path modulesDir) {
this.modulesDir = modulesDir
this.logger = Logging.getLogger(this.class)
}
@Override
void beforeResolve(ResolvableDependencies dependencies) {
// nothing to do
}
@Override
void afterResolve(ResolvableDependencies dependencies) {
// We process only module dependencies
if (dependencies.path.startsWith(":modules:") &&
dependencies.name == "compileClasspath") {
def projectName = dependencies.path.split(":")[2]
if (!dependencies.artifacts.artifacts.empty) {
logger.debug("\nProcessing module '{}' in a multi-project workspace", projectName)
}
dependencies.artifacts.artifacts.each {
if (isRemoteTerasologyModule(it)) {
println "$projectName resolved binary $it"
def binaryModulePath = modulesDir.resolve(it.file.name)
Files.copy(it.file.toPath(), binaryModulePath, StandardCopyOption.REPLACE_EXISTING)
} else if (isLocalTerasologyModule(it)) {
logger.info("*** Found module dependency {} in source form, not copying a runtime jar from Gradle", it)
} else {
//ignore non terasology module
}
}
}
}
private static boolean isRemoteTerasologyModule(ResolvedArtifactResult artifact) {
def componentIdentifier = artifact.id.componentIdentifier
if (componentIdentifier instanceof ModuleComponentIdentifier) {
def module = componentIdentifier as ModuleComponentIdentifier
return module.group == 'org.terasology.modules'
}
return false
}
private static boolean isLocalTerasologyModule(ResolvedArtifactResult artifact) {
def componentIdentifier = artifact.id.componentIdentifier
if (componentIdentifier instanceof ProjectComponentIdentifier) {
def module = componentIdentifier as ProjectComponentIdentifier
return !(module.projectName in ['engine', 'engine-tests'])
}
return false
}
}
gradle.addListener(new RemoteModuleGatherer(rootDir.toPath().resolve("modules")))
tasks.named('wrapper') {
// ALL distributionType because IntelliJ prefers having its sources for analysis and reference.
distributionType = Wrapper.DistributionType.ALL
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// General IDE customization //
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
task copyInMissingTemplates {
description = "Copies in placeholders from the /templates dir to project root if not present yet"
File gradlePropsFile = new File(rootDir, 'gradle.properties')
File OverrideCfgFile = new File(rootDir, 'override.cfg')
if (!gradlePropsFile.exists()) {
new File(rootDir, 'gradle.properties') << new File(templatesDir, 'gradle.properties').text
}
if (!OverrideCfgFile.exists()) {
new File(rootDir, 'override.cfg') << new File(templatesDir, 'override.cfg').text
}
}
// Make sure the IDE prep includes extraction of natives
ideaModule.dependsOn extractNatives
ideaModule.dependsOn copyInMissingTemplates
// For IntelliJ add a bunch of excluded directories
idea {
// Exclude Eclipse dirs
// TODO: Update this as Eclipse bin dirs now generate in several deeper spots rather than at top-level
module.excludeDirs += file('bin')
module.excludeDirs += file('.settings')
// TODO: Add a single file exclude for facades/PC/Terasology.launch ?
// Exclude special dirs
module.excludeDirs += file('natives')
module.excludeDirs += file('protobuf')
// Exclude output dirs
module.excludeDirs += file('configs')
module.excludeDirs += file('logs')
module.excludeDirs += file('saves')
module.excludeDirs += file('screenshots')
module.excludeDirs += file('terasology-server')
module.excludeDirs += file('terasology-2ndclient')
module.downloadSources = true
project.settings.delegateActions {
delegateBuildRunToGradle = false
testRunner = ActionDelegationConfig.TestRunner.PLATFORM
}
}
cleanIdea.doLast {
new File('Terasology.iws').delete()
}