forked from MovingBlocks/Terasology
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.gradle
267 lines (219 loc) · 9.78 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
/*
* This is a Gradle build file:
* - Gradle Homepage: http://gradle.org/
* - Gradle Documentation: http://gradle.org/documentation
* - View tasks for this project: $ gradlew tasks
*/
// Separate build file for structure heavy stuff like using Git to fetch other repos to embed within the project
apply from: 'config/gradle/utility.gradle'
apply from: 'config/gradle/ide.gradle'
// Needed for extending the "clean" task to also delete custom stuff defined here like natives
apply plugin: 'base'
// For generating IntelliJ project files
apply plugin: 'idea'
// The root project should not be an eclipse project. It keeps eclipse (4.2) from finding the sub-projects.
//apply plugin: 'eclipse'
// Git plugin details at https://github.com/ajoberstar/gradle-git
import org.ajoberstar.gradle.git.tasks.*
// Dependencies needed for what our Gradle scripts themselves use. It cannot be included via an external Gradle file :-(
buildscript {
repositories {
mavenCentral()
maven {
url 'http://dl.bintray.com/jfrog/jfrog-jars'
}
}
dependencies {
// Artifactory plugin
classpath(group: 'org.jfrog.buildinfo', name: 'build-info-extractor-gradle', version: '2.2.3')
// Git plugin for Gradle
classpath 'org.ajoberstar:gradle-git:0.6.3'
// Needed for caching reflected data during builds
classpath 'org.reflections:reflections:0.9.9'
classpath 'dom4j:dom4j:1.6.1'
}
}
/*
* To Update Gradle Wrapper:
* 1. Uncomment 'wrapper' task
* 2. Change 'gradleVersion'
* 3. Run "gradlew wrapper" TWICE (first upgrades the prop file, second the jar if needed)
* 4. Comment 'wrapper' task
*/
//task wrapper(type: Wrapper) {
// gradleVersion = '2.1'
//}
import org.apache.tools.ant.filters.FixCrLfFilter;
// Test for right version of Java in use for running this script
assert org.gradle.api.JavaVersion.current().isJava7Compatible()
// Declare "extra properties" (variables) for the project (and subs) - a Gradle thing that makes them special.
ext {
dirNatives = 'natives'
templatesDir = 'templates'
// Lib dir for use in manifest entries etc (like in :engine). A separate "libsDir" exists, auto-created by Gradle
subDirLibs = 'libs'
LwjglVersion = '2.9.2'
}
// Declare remote repositories we're interested in - library files will be fetched from here
repositories {
// Main Maven repo
mavenCentral()
// MovingBlocks Artifactory instance for libs not readily available elsewhere plus our own libs
maven {
url "http://artifactory.terasology.org:8081/artifactory/virtual-repo-live"
}
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// 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 group: 'org.lwjgl.lwjgl', name: 'lwjgl', version: LwjglVersion
// Config for our code analytics lives in a centralized repo: https://github.com/MovingBlocks/TeraConfig
codeMetrics group: 'org.terasology.config', name: 'codemetrics', version: '1.0.0', ext: 'zip'
}
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 OSX 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 = "Extracts all the native lwjgl libraries from the downloaded zip"
dependsOn extractWindowsNatives
dependsOn extractLinuxNatives
dependsOn extractMacOSXNatives
}
// TODO: Test meta modules and other libs - not that there's really much to test other than being able to Git via Gradle
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// 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/config"
}
// Helper that returns a list of all local Terasology module projects
def terasologyModules() {
subprojects.findAll {it.parent.name == 'modules'}
}
// Helper that replaces the build.gradle under every module with a fresh copy from the Core module
// TODO: Fix, not working well if at all :(
task refreshModuleGradle << {
File replacementGradle = new File(rootDir, 'modules/Core/build.gradle')
terasologyModules().each {
if (it.name != 'Core') {
File targetFile = new File(rootDir, "modules/" + it.name + "/build.gradle")
targetFile.delete()
targetFile << replacementGradle.text
}
}
}
// 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()
println "Cleaned root - don't forget to re-extract the natives! 'gradlew extractNatives' or a dependent task"
}
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"
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// General IDE customization //
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Make sure the IDE prep includes extraction of natives
ideaModule.dependsOn extractNatives
// 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('logs')
module.excludeDirs += file('saves')
module.excludeDirs += file('screenshots')
module.excludeDirs += file('terasology-server')
module.excludeDirs += file('terasology-2ndclient')
module.downloadSources = true
project {
// Set JDK
jdkName = '1.8'
wildcards -= '!?*.groovy'
ipr {
withXml { xmlProvider ->
// Apply a bunch of tweaks to IntelliJ config - all defined in ide.gradle
// Part reason for separate file was in case a module needs to define something it cannot do so in a project block
def iprNode = xmlProvider.asNode()
ideaActivateCheckstyle(iprNode)
ideaActivateCopyright(iprNode)
ideaActivateAnnotations(iprNode)
ideaActivateGit(iprNode)
ideaActivateGradle(iprNode)
}
// Sets sourceCompatibility within IntelliJ (without this root build having the Java plugin applied)
whenMerged {project ->
project.jdk.languageLevel = 'JDK_1_8'
}
}
}
// Tweaks to the .iws
workspace.iws.withXml { xmlProvider ->
def iwsNode = xmlProvider.asNode()
ideaMakeAutomatically(iwsNode)
ideaRunConfig(iwsNode)
}
}
cleanIdea.doLast {
new File('Terasology.iws').delete()
}