-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathbuild.gradle
179 lines (145 loc) · 5.45 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
plugins {
id "org.standardout.versioneye" version "1.0.1"
}
apply plugin: 'java'
apply plugin: 'maven'
apply plugin: 'eclipse'
apply plugin: 'idea'
apply plugin: 'checkstyle'
apply plugin: 'pmd'
apply plugin: 'findbugs'
apply plugin: 'application'
group = 'org.terasology'
version = getFullVersion()
sourceCompatibility = 1.8
targetCompatibility = 1.8
mainClassName = 'org.terasology.world.viewer.WorldViewer'
applicationDefaultJvmArgs = ["-Xmx3g"]
// We use both Maven Central and our own Artifactory instance, which contains module builds, extra libs, and so on
repositories {
mavenCentral()
maven {
url "http://artifactory.terasology.org/artifactory/virtual-repo-live"
}
}
def getGitDesc() {
def cmd = 'git describe --long --match *.*.0'
try {
def proc = cmd.execute()
proc.waitFor() // wait for the command to finish
def desc = proc.in.text.trim() // "out" from the process is "in" for gradle
return desc;
} catch (IOException e) {
logger.warn("Could not run '$cmd'")
return "0.0.0-0-0000000"
}
}
def getVersionInfo() {
def desc = getGitDesc()
def matcher = desc =~ "(\\d+)\\.(\\d+)\\.0-(\\d+)-g([0-9A-Za-z]*)"
if (!matcher || !matcher.matches()) {
logger.warn("Version '$desc' does not match format: 'd.d.0-d-gHHHHHHH'")
return ["0", "0", "0", "0000000"]
} else {
def major = matcher.group(1)
def minor = matcher.group(2)
def patch = matcher.group(3)
def sha = matcher.group(4)
return [major, minor, patch, sha]
}
}
def getFullVersion() {
def (major, minor, patch, sha) = getVersionInfo()
return "$major.$minor.$patch+$sha";
}
task createVersionFile(type:Copy) {
description = 'Creates a java version file based on the template in the resources folder'
inputs.property('version', version) // trigger executing by setting a property
from ('src/main/resources/VersionInfo.template')
into ('src/main/java/org/terasology/world/viewer/version')
rename '(.*).template', '$1.java'
def (major, minor, patch, sha) = getVersionInfo()
expand(
BUILD_VERSION_MAJOR: major,
BUILD_VERSION_MINOR: minor,
BUILD_VERSION_PATCH: patch,
BUILD_SHA: sha,
BUILD_TIME: java.time.ZonedDateTime.now().toString());
}
task wrapper(type: Wrapper) {
gradleVersion = '2.3'
}
compileJava.dependsOn createVersionFile
eclipseProject.dependsOn createVersionFile
configurations {
codeMetrics
}
dependencies {
codeMetrics(group: 'org.terasology.config', name: 'codemetrics', version: '1.0.0', ext: 'zip')
checkstyle ('com.puppycrawl.tools:checkstyle:6.7')
pmd ('net.sourceforge.pmd:pmd-core:5.3.3')
pmd ('net.sourceforge.pmd:pmd-java:5.3.3')
compile (group: 'org.terasology.modules', name: 'Core', version: '1.2.1-SNAPSHOT')
// compile (group: 'org.terasology.modules', name: 'Cities', version: '+')
// compile (group: 'org.terasology.modules', name: 'Pathfinding', version: '+')
// compile (group: 'org.terasology.modules', name: 'TutorialWorldGeneration', version: '+')
// compile (group: 'org.terasology.modules', name: 'LightAndShadow', version: '+')
// compile (group: 'org.terasology.modules', name: 'WoodAndStone', version: '+')
// compile (group: 'org.terasology.modules', name: 'PolyWorld', version: '+')
// Mockups for Environments
compile (group: 'org.mockito', name: 'mockito-all', version: '1.10.19')
}
task sourceJar(type: Jar) {
description = "Create a JAR with all sources"
from sourceSets.main.allSource
classifier = 'sources'
}
task javadocJar(type: Jar, dependsOn: javadoc) {
description = "Create a JAR with the JavaDoc for the java sources"
from javadoc.destinationDir
classifier = 'javadoc'
}
// Define the artifacts we want to publish (the .pom will also be included since the Maven plugin is active)
artifacts {
archives sourceJar
archives javadocJar
}
jar {
manifest {
attributes("Main-Class": mainClassName)
attributes("Class-Path" : configurations.runtime.collect { it.getName() }.join(" "))
attributes("Implementation-Title": "WorldViewer")
attributes("Implementation-Version": version)
}
}
distZip {
// remove the version number from the zip file name
// the name of the zip file will thus be independent from the version
version = ''
}
checkstyle {
ignoreFailures = true
config = resources.text.fromArchiveEntry(configurations.codeMetrics, "checkstyle/checkstyle.xml")
// this assigns the property variable ${samedir} in checkstyle.xml
configProperties.samedir = config.asFile().parent
}
configure([checkstyleMain, checkstyleTest]) {
doFirst {
def suppressions = resources.text.fromArchiveEntry(configurations.codeMetrics, "checkstyle/suppressions.xml")
// the asFile() method extracts the file from the zip archive and puts it next to checkstyle.xml
// this procedure should not be done in the config phase, since the clean task would erase the file before it can be used
suppressions.asFile()
}
}
pmd {
ignoreFailures = true
ruleSetConfig = resources.text.fromArchiveEntry(configurations.codeMetrics, "pmd/pmd.xml")
ruleSets = []
}
findbugs {
ignoreFailures = true
effort = 'max'
reportLevel = 'medium'
toolVersion = '3.0.1'
excludeFilterConfig = resources.text.fromArchiveEntry(configurations.codeMetrics, "findbugs/findbugs-exclude.xml")
}