-
Notifications
You must be signed in to change notification settings - Fork 76
/
build.gradle
329 lines (265 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
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
// Copyright 2020 The Terasology Foundation
// SPDX-License-Identifier: Apache-2.0
buildscript {
repositories {
mavenCentral()
gradlePluginPortal()
}
configurations.classpath {
resolutionStrategy.activateDependencyLocking()
}
}
plugins {
id("application")
id("checkstyle")
id("com.github.spotbugs") version "5.2.3"
id("de.undercouch.download") version "5.3.0"
id("java")
// to help clarify conflicting logging providers
id("name.remal.component-metadata") version "1.5.0"
id("nebula.release") version "16.0.0"
id("pmd")
id("project-report")
id("org.openjfx.javafxplugin") version "0.0.13"
id("org.jetbrains.gradle.plugin.idea-ext") version "1.1.5"
}
apply plugin: "org.terasology.gradlegoo"
apply from: "./config/gradle/jre.gradle"
// Test for right version of Java in use for running this script
assert JavaVersion.current().isJava11Compatible()
import org.apache.tools.ant.filters.FixCrLfFilter
import java.text.SimpleDateFormat
def dateTimeFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssXXX")
dateTimeFormat.timeZone = TimeZone.getTimeZone("UTC")
configurations {
compileClasspath {
resolutionStrategy.activateDependencyLocking()
}
codeMetrics
}
// Declare "extra properties" (variables) for the project - a Gradle thing that makes them special.
ext {
// Read environment variables, including variables passed by jenkins continuous integration server
env = System.getenv()
// Stuff for our automatic version file setup
startDateTimeString = dateTimeFormat.format(new Date())
// Splash image for the JAR
splashImage = "org/terasology/launcher/images/splash.jpg"
// Shared code analytics configurations via retrieved config zip
metricsConfigDir = layout.getProjectDirectory().dir("config/metrics")
}
// Declare remote repositories we're interested in - library files will be fetched from here
repositories {
// Main Maven repo
mavenCentral()
maven {
// MovingBlocks Artifactory instance(s) for libs not readily available elsewhere plus our own libs
name "Terasology Artifactory"
url "https://artifactory.terasology.io/artifactory/virtual-repo-live"
}
maven {
name "JitPack" // used by org.everit.json.schema
url "https://jitpack.io"
}
maven {
// required for markdown-javafx-renderer
url "https://sandec.jfrog.io/artifactory/repo"
}
}
// Primary dependencies definition
dependencies {
implementation("org.slf4j:slf4j-api:[1.7.+, 2.0.0-alpha7]") {
because "influenced by app or test loggers as needed"
}
implementation("ch.qos.logback:logback-classic:1.3.0-alpha16") {
because "1.3 series uses ServiceLoader (more packaging friendly?)"
}
implementation("com.google.code.gson:gson:2.8.5")
implementation("com.google.guava:guava:31.1-jre")
implementation("com.github.everit-org.json-schema:org.everit.json.schema:1.14.1")
implementation("org.kohsuke:github-api:1.318")
implementation("org.semver4j:semver4j:5.2.2")
implementation("com.vladsch.flexmark:flexmark-all:0.64.0")
implementation("org.hildan.fxgson:fx-gson:5.0.0") {
because "de-/serialization of launcher properties to JSON"
}
implementation("com.squareup.okhttp3:okhttp:4.12.0") {
because "built-in caching of HTTP requests"
}
// These dependencies are only needed for running tests
testImplementation("org.hamcrest:hamcrest:2.2")
testImplementation("org.junit.jupiter:junit-jupiter-api:5.10.2")
testImplementation("org.junit.jupiter:junit-jupiter-params:5.10.2")
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:5.10.2")
testImplementation("org.mockito:mockito-inline:5.2.0") {
because "-inline build enables mocking final classes"
// https://javadoc.io/doc/org.mockito/mockito-core/latest/org/mockito/Mockito.html#0.2
// > Be aware that this artifact may be abolished when the inline mock making feature is integrated into the default mock maker.
}
testImplementation("org.mockito:mockito-junit-jupiter:5.2.0")
testImplementation("org.spf4j:spf4j-slf4j-test:8.10.0") {
because "testable logging"
}
testImplementation("org.slf4j:slf4j-api:2.0.13")
testImplementation("org.testfx:testfx-core:4.0.18") {
because "to test JavaFX Application"
// -alpha because that's the only kind of release they have?
}
testImplementation("org.testfx:testfx-junit5:4.0.18")
testImplementation("org.testfx:openjfx-monocle:17.0.10") {
// nobody's uploaded a jdk-14 build yet. does the jdk-12 one work?
because "CI builders are headless environments"
}
testImplementation("com.github.gmazzo.okhttp.mock:mock-client:2.0.0") {
because "to easily write OkHttpClient interceptors for testing"
}
testImplementation("com.squareup.okhttp3:mockwebserver:4.10.0") {
because "to control server responses for testing"
}
// Config for our code analytics from: https://github.com/MovingBlocks/TeraConfig
codeMetrics group: "org.terasology.config", name: "codemetrics", version: "1.7.1", ext: "zip"
}
configurations.matching({ it =~ ~/test(Runtime|Compile|Implementation|PmdAux)Classpath/ }).all {
resolutionStrategy(gradlegoo.prefers("logging", "jcl-api-capability", "jcl-over-slf4j",
"jcl should prefer slf4j when available"))
resolutionStrategy(gradlegoo.prefers("logging", "slf4j-impl-capability",
"spf4j-slf4j-test", "tests use slf4j-test"))
// SPF4J has a dependency on "avro-logical-types-gen:1.3", which does not exist. However, version "1.3p" does.
resolutionStrategy.force("org.spf4j:avro-logical-types-gen:1.3p")
// old hamcrest versions exist only to spite us
// http://hamcrest.org/JavaHamcrest/distributables#upgrading-from-hamcrest-1x
exclude group: "org.hamcrest", module: "hamcrest-core"
exclude group: "org.hamcrest", module: "hamcrest-library"
}
// Set the expected module Java level (can use a higher Java to run, but should not use features from a higher Java)
sourceCompatibility = 1.11
targetCompatibility = 1.11
compileJava.options.encoding = "UTF-8"
compileTestJava.options.encoding = "UTF-8"
javafx {
version = "17.0.2"
modules = [
"javafx.graphics",
"javafx.fxml",
"javafx.web"
]
}
test {
useJUnitPlatform()
// The SPF4J test dependency relies on some forbidden reflection to improve logging performance.
// Java 17 will not tolerate this without a bit of encouragement.
jvmArgs("--add-opens=java.logging/java.util.logging=ALL-UNNAMED")
}
checkstyle {
toolVersion = "10.4"
ignoreFailures = false
configDirectory.set(metricsConfigDir.dir("checkstyle"))
}
pmd {
toolVersion = "6.39.0"
ignoreFailures = false
consoleOutput = true
threads = 4
ruleSetFiles "${rootDir}/config/pmd.xml"
ruleSets = []
}
spotbugs {
ignoreFailures = true
effort = "max"
reportLevel = "medium"
}
mainClassName = "org.terasology.launcher.TerasologyLauncher"
def convertGitBranch = { gitBranch ->
if (gitBranch != null) {
// Remove "origin/" from "origin/develop"
gitBranch.substring(gitBranch.lastIndexOf("/") + 1)
} else {
""
}
}
task createVersionInfoFile {
inputs.property("version", version.toString())
File versionInfoFileDir = new File(sourceSets.main.output.resourcesDir, "org/terasology/launcher/")
File versionFile = new File(versionInfoFileDir, "version.txt")
outputs.file(versionFile)
doLast {
versionInfoFileDir.mkdirs()
versionFile.text = version
}
}
task extractCodeMetricsConfig(type: Copy) {
description = "Extract code metrics configuration to '$metricsConfigDir'"
from {
configurations.codeMetrics.collect {
zipTree(it)
}
}
into metricsConfigDir
}
processResources.dependsOn(createVersionInfoFile, extractCodeMetricsConfig)
clean {
delete createVersionInfoFile.outputs.files
delete extractCodeMetricsConfig.destinationDir
}
processResources.dependsOn(createVersionInfoFile)
jar {
//TODO we only use this name because the `.exe` start scripts require the JAR to be named "TerasologyLauncher.jar"
jar.archiveFileName = "${project.name}.jar"
// replace development "logback.xml" with productive "logback_jar.xml"
exclude "logback.xml"
rename("logback_jar.xml", "logback.xml")
manifest {
def manifestClasspath = configurations.runtimeClasspath.collect { it.getName() }.join(" ")
attributes("Main-Class": mainClassName)
attributes("Class-Path": manifestClasspath)
attributes("Implementation-Title": project.name)
attributes("Implementation-Version": project.version)
attributes("SplashScreen-Image": splashImage)
// allow everything
attributes("Permissions": "all-permissions")
attributes("Codebase": "*")
attributes("Application-Name": project.name)
attributes("Application-Library-Allowable-Codebase": "*")
attributes("Caller-Allowable-Codebase": "*")
attributes("Trusted-Only": "false")
}
}
task copyExtra(type: Copy) {
filter(FixCrLfFilter, eol: FixCrLfFilter.CrLf.newInstance("crlf"))
from("README.md") {
rename("README.md", "README.txt")
}
from("CHANGELOG.md") {
rename("CHANGELOG.md", "CHANGELOG.txt")
}
from("CONTRIBUTING.md") {
rename("CONTRIBUTING.md", "CONTRIBUTING.txt")
}
from("LICENSE")
from("NOTICE")
into "$buildDir/distributions"
}
task copyExtraIntoResources(type: Copy) {
from("README.md")
from("CHANGELOG.md")
from("docs/CONTRIBUTING.md")
from("LICENSE")
into("src/main/resources/org/terasology/launcher/about")
}
processResources.dependsOn copyExtraIntoResources
task copyIconsIntoResources(type: Copy) {
from("icons")
into("src/main/resources/org/terasology/launcher/icons")
}
processResources.dependsOn copyIconsIntoResources
//TODO: Temporary workaround for new exes / JRE bundling not quite being officially ready yet
distZip.exclude("*.x*.exe")
idea {
project.settings.delegateActions {
delegateBuildRunToGradle = false
}
}
tasks.named("wrapper") {
// IDEA likes this distribution to better know things.
distributionType = Wrapper.DistributionType.ALL
}