forked from MovingBlocks/Terasology
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.gradle
284 lines (232 loc) · 10.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
278
279
280
281
282
283
284
// Copyright 2021 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 {
mavenCentral()
google()
gradlePluginPortal()
maven {
// required to provide runtime dependencies to build-logic.
name = "Terasology Artifactory"
url = "http://artifactory.terasology.org/artifactory/virtual-repo-live"
allowInsecureProtocol = true // 😱
}
// TODO MYSTERY: As of November 7th 2011 virtual-repo-live could no longer be relied on for latest snapshots - Pro feature?
// We've been using it that way for *years* and nothing likewise changed in the area for years as well. This seems to work ....
maven {
name = "Terasology snapshot locals"
url = "http://artifactory.terasology.org/artifactory/terasology-snapshot-local"
allowInsecureProtocol = true // 😱
}
}
dependencies {
// Our locally included /build-logic
classpath("org.terasology.gradology:build-logic")
}
}
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 "1.0"
id("com.google.protobuf") version "0.8.16" apply false
id("terasology-repositories")
}
import org.gradle.internal.logging.text.StyledTextOutputFactory
import org.jetbrains.gradle.ext.ActionDelegationConfig
import org.terasology.gradology.CopyButNeverOverwrite
import static org.gradle.internal.logging.text.StyledTextOutput.Style
// Test for right version of Java in use for running this script
assert org.gradle.api.JavaVersion.current().isJava11Compatible()
if(!(JavaVersion.current() == JavaVersion.VERSION_11)) {
def out = services.get(StyledTextOutputFactory).create("an-ouput")
out.withStyle(Style.FailureHeader).println("""
WARNING: Compiling with a JDK of not version 11. While some other Javas may be
safe to use, any newer than 11 may cause issues.
If you encounter oddities try Java 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 = file('templates')
// Lib dir for use in manifest entries etc (like in :engine). A separate "libsDir" exists, auto-created by Gradle
subDirLibs = 'libs'
LwjglVersion = '3.3.1'
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// 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.6.3', 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"
}
// 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"
}
// 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}")
}
}
}
}
tasks.named('wrapper') {
// ALL distributionType because IntelliJ prefers having its sources for analysis and reference.
distributionType = Wrapper.DistributionType.ALL
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// General IDE customization //
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
tasks.register("copyInMissingTemplates", CopyButNeverOverwrite) {
description = "Copies in placeholders from the /templates dir to project root if not present yet"
from(templatesDir)
into(rootDir)
include('gradle.properties', 'override.cfg')
}
tasks.register("jmxPassword", CopyButNeverOverwrite) {
description = "Create config/jmxremote.password from a template."
setFileMode(0600) // passwords must be accessible only by owner
// there is a template file in $JAVA_HOME/conf/management
from(java.nio.file.Path.of(System.getProperty("java.home"), "conf", "management"))
include("jmxremote.password.template")
rename("(.*).template", '$1')
into("config")
doLast {
logger.warn("${it.outputs.files.singleFile}/jmxremote.password:100: Edit this to set your password.")
}
}
// 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.CHOOSE_PER_TEST
}
}
cleanIdea.doLast {
new File('Terasology.iws').delete()
}