forked from MovingBlocks/Terasology
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.gradle
247 lines (205 loc) · 9.46 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
/*
* This is a Gradle build file:
* - Gradle Homepage: http://gradle.org/
* - Gradle Documentation: http://gradle.org/documentation
* - View tasks for this project: $ gradlew tasks
*/
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'
apply plugin: 'checkstyle'
apply plugin: 'pmd'
// Separate build file for structure heavy stuff like using Git to fetch other repos to embed within the project
apply from: 'utility.gradle'
apply from: 'ide.gradle'
/*
* 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 = '1.8'
//}
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 {
// Version levels for LWJGL
LWJGL_VERSION = '2.9.0'
JINPUT_VERSION = '2.0.5'
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'
}
// 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://www.movingblocks.net:8081/artifactory/repo"
}
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Natives - Handles pulling in and extracting native libraries for LWJGL //
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Define a custom configuration named "natives"
configurations {
natives
}
// For the "natives" configuration make it depend on the native files from LWJGL
dependencies {
natives group: 'org.lwjgl.lwjgl', name: 'lwjgl', version: LWJGL_VERSION
}
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
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Section for project modules (equally set up as modules in IntelliJ) //
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Move this to the generated subproject gradle files? Or use project.childProjects even here?
// TODO: This pretty much has been made obsolete by changes elsewhere. Do a last check (especially of libs) then remove
subprojects {
// MODULES - most "exposed" project component type, users will supply these so need to be careful
if (project.getParent().name == "modules" ) {
// TODO: Verify a user-provided build.gradle cannot override the one we create
// Maybe Jenkins module builds should delete if exists then re-copy in from main project ?
println "Iterating over subprojects - Found a module: $project.name"
} else if (project.getParent().name == "facades" ) {
// FACADES - front-ends to the engine, fully under our control
println "Iterating over subprojects - Found a facade: " + project.name
} else if (project.getParent().name == "libs" ) {
println "Iterating over subprojects - Found a lib: " + project.name
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'idea'
}
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Helper tasks //
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// 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
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'
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// General IDE customization //
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Make sure the IDE prep includes extraction of natives
ideaModule.dependsOn extractNatives
// TODO: This next piece broke when the root build had its java plugin removed
//eclipseClasspath.dependsOn extractNatives
// For IntelliJ add a bunch of excluded directories
idea {
// Exclude Eclipse dirs
module.excludeDirs += file('bin')
module.excludeDirs += file('.settings')
// Exclude special dirs
module.excludeDirs += file('natives')
module.excludeDirs += file('protobuf')
module.excludeDirs += file('gradle')
// Exclude output dirs
module.excludeDirs += file('logs')
module.excludeDirs += file('saves')
module.excludeDirs += file('screenshots')
project {
// Set JDK
jdkName = '1.7'
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_7'
}
}
}
// Tweaks to the .iws
workspace.iws.withXml { xmlProvider ->
def iwsNode = xmlProvider.asNode()
ideaMakeAutomatically(iwsNode)
ideaRunConfig(iwsNode)
}
}
cleanIdea.doLast {
new File('Terasology.iws').delete()
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Checkstyle stuff //
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// TODO: Should probably put this in a separate Gradle file and import everywhere. Maybe a Java version too with sourceCompatibility?
checkstyle {
ignoreFailures = true
configFile = new File(rootDir, 'config/checkstyle/checkstyle.xml')
configProperties.samedir = checkstyle.configFile.parentFile
}
pmd {
ignoreFailures = true
ruleSetFiles = files("$rootDir/config/pmd/pmd.xml")
}