forked from wpilibsuite/shuffleboard
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.gradle.kts
334 lines (298 loc) · 11.1 KB
/
build.gradle.kts
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
330
331
332
333
334
import com.diffplug.spotless.FormatterStep
import com.github.spotbugs.SpotBugsTask
import com.github.spotbugs.SpotBugsExtension
import org.gradle.api.Project
import org.gradle.api.publish.maven.MavenPublication
import org.gradle.jvm.tasks.Jar
import org.gradle.testing.jacoco.tasks.JacocoReport
import java.time.Instant
import org.jfrog.gradle.plugin.artifactory.dsl.PublisherConfig
import groovy.lang.GroovyObject
buildscript {
repositories {
mavenCentral()
jcenter()
}
}
plugins {
`maven-publish`
jacoco
id("edu.wpi.first.wpilib.versioning.WPILibVersioningPlugin") version "4.0.1"
id("edu.wpi.first.wpilib.repositories.WPILibRepositoriesPlugin") version "2020.1"
id("com.jfrog.artifactory") version "4.9.8"
id("com.github.johnrengelman.shadow") version "4.0.3"
id("com.diffplug.gradle.spotless") version "3.13.0"
id("com.github.spotbugs") version "1.6.4"
id("com.google.osdetector") version "1.4.0"
}
if (hasProperty("buildServer")) {
wpilibVersioning.setBuildServerMode(true)
}
if (hasProperty("releaseMode")) {
wpilibVersioning.setReleaseMode(true)
}
allprojects {
repositories {
mavenCentral()
}
if (hasProperty("releaseMode")) {
rootProject.wpilibRepositories.addAllReleaseRepositories(project)
} else {
rootProject.wpilibRepositories.addAllDevelopmentRepositories(project)
}
}
wpilibVersioning.getVersion().finalizeValue()
// Only load the project version once, then share it
val projectVersion = wpilibVersioning.getVersion().get()
allprojects {
apply {
plugin("com.diffplug.gradle.spotless")
plugin("com.jfrog.artifactory")
}
if (System.getenv()["RUN_AZURE_ARTIFACTORY_RELEASE"] != null) {
artifactory {
setContextUrl("https://frcmaven.wpi.edu/artifactory") // base artifactory url
publish(delegateClosureOf<PublisherConfig> {
repository(delegateClosureOf<GroovyObject> {
if (project.hasProperty("releaseMode")) {
setProperty("repoKey", "release")
} else {
setProperty("repoKey", "development")
}
setProperty("username", System.getenv()["ARTIFACTORY_PUBLISH_USERNAME"])
setProperty("password", System.getenv()["ARTIFACTORY_PUBLISH_PASSWORD"])
setProperty("maven", true)
})
})
clientConfig.info.setBuildName("Shuffleboard")
}
}
version = projectVersion
// Note: plugins should override this
tasks.withType<Jar>().configureEach {
manifest {
attributes["Implementation-Version"] = project.version as String
attributes["Built-Date"] = Instant.now().toString()
}
}
// Spotless is used to lint and reformat source files.
spotless {
kotlinGradle {
ktlint("0.24.0")
trimTrailingWhitespace()
indentWithSpaces()
endWithNewline()
}
format("extraneous") {
target("*.sh", "*.yml")
trimTrailingWhitespace()
indentWithSpaces()
endWithNewline()
}
format("markdown") {
target("*.md")
// Default timeWhitespace() doesn't respect lines ending with two spaces for a tight line break
// So we have to implement it ourselves
class TrimTrailingSpaces : FormatterStep {
override fun getName(): String = "trimTrailingSpaces"
override fun format(rawUnix: String, file: File) = rawUnix
.split('\n')
.joinToString(separator = "\n", transform = this::formatLine)
fun formatLine(line: String): String {
if (!line.endsWith(" ")) {
// No trailing whitespace
return line
}
if (line.matches(Regex("^.*[^ \t] {2}$"))) {
// Ends with two spaces - it's a tight line break, so leave it
return line
}
val endsWithMoreThanTwoSpaces = Regex("^(.*[^ \t]) {3,}^")
val match = endsWithMoreThanTwoSpaces.matchEntire(line)
if (match != null) {
// Ends with at least 3 spaces
// Trim the excess, but leave two spaces at the end for a tight line break
return match.groupValues[1] + " "
}
if (line.endsWith(" ")) {
// Ends with a single space - remove it
return line.substring(0, line.length - 1)
}
// Not sure how we got here; every case should have been covered.
// Print an error but do not change the line
System.err.println("Could not trim whitespace from line '$line'")
return line
}
}
addStep(TrimTrailingSpaces())
indentWithSpaces()
endWithNewline()
}
}
}
allprojects {
apply {
plugin("java")
plugin("checkstyle")
plugin("pmd")
plugin("com.github.spotbugs")
plugin("jacoco")
plugin("maven-publish")
}
repositories {
mavenCentral()
}
createNativeConfigurations()
dependencies {
fun junitJupiter(name: String, version: String = "5.2.0") =
create(group = "org.junit.jupiter", name = name, version = version)
"compileOnly"(create(group = "com.google.code.findbugs", name = "annotations", version = "3.0.1"))
"testCompile"(junitJupiter(name = "junit-jupiter-api"))
"testCompile"(junitJupiter(name = "junit-jupiter-engine"))
"testCompile"(junitJupiter(name = "junit-jupiter-params"))
"testCompile"(group = "org.junit-pioneer", name = "junit-pioneer", version = "0.3.0")
"testRuntime"(group = "org.junit.platform", name = "junit-platform-launcher", version = "1.0.0")
fun testFx(name: String, version: String = "4.0.13-alpha") =
create(group = "org.testfx", name = name, version = version)
"testCompile"(testFx(name = "testfx-core"))
"testCompile"(testFx(name = "testfx-junit5"))
"testRuntime"(testFx(name = "openjfx-monocle", version = "jdk-9+181"))
javafx("base")
javafx("controls")
javafx("fxml")
javafx("graphics")
}
checkstyle {
toolVersion = "8.12"
}
pmd {
toolVersion = "6.7.0"
isConsoleOutput = true
sourceSets = setOf(java.sourceSets["main"])
reportsDir = file("${project.buildDir}/reports/pmd")
ruleSetFiles = files(file("$rootDir/pmd-ruleset.xml"))
ruleSets = emptyList()
}
spotbugs {
toolVersion = "3.1.7"
sourceSets = setOf(java.sourceSets["main"], java.sourceSets["test"])
excludeFilter = file("$rootDir/findBugsSuppressions.xml")
effort = "max"
}
tasks.withType<JavaCompile> {
// UTF-8 characters are used in menus
options.encoding = "UTF-8"
}
tasks.withType<SpotBugsTask> {
reports {
xml.isEnabled = false
emacs.isEnabled = true
}
finalizedBy(task("${name}Report") {
mustRunAfter(this@withType)
doLast {
this@withType
.reports
.emacs
.destination
.takeIf { it.exists() }
?.readText()
.takeIf { !it.isNullOrBlank() }
?.also { logger.warn(it) }
}
})
}
jacoco {
toolVersion = "0.8.2"
}
tasks.withType<JacocoReport> {
reports {
xml.isEnabled = true
html.isEnabled = true
}
}
tasks.withType<Test> {
// TODO: re-enable when TestFX (or the underlying JavaFX problem) is fixed
println("UI tests will not be run due to TestFX being broken when headless on Java 10.")
println("See: https://github.com/javafxports/openjdk-jfx/issues/66")
// Link: https://github.com/javafxports/openjdk-jfx/issues/66
useJUnitPlatform {
excludeTags("UI")
}
}
tasks.withType<Javadoc> {
isFailOnError = false
}
}
project(":api") {
val sourceJar = task<Jar>("sourceJar") {
description = "Creates a JAR that contains the source code."
from(java.sourceSets["main"].allSource)
classifier = "sources"
}
val javadocJar = task<Jar>("javadocJar") {
dependsOn("javadoc")
description = "Creates a JAR that contains the javadocs."
from(java.docsDir)
classifier = "javadoc"
}
if (System.getenv()["RUN_AZURE_ARTIFACTORY_RELEASE"] != null) {
artifactory {
publish(delegateClosureOf<PublisherConfig> {
defaults(delegateClosureOf<GroovyObject> {
invokeMethod("publications", "api")
})
})
}
}
publishing {
publications {
create<MavenPublication>("api") {
groupId = "edu.wpi.first.shuffleboard"
artifactId = "api"
version = project.version.toString()
afterEvaluate {
from(components["java"])
}
artifact(sourceJar)
artifact(javadocJar)
}
}
}
}
tasks.withType<Wrapper>().configureEach {
gradleVersion = "5.0"
}
/**
* Retrieves the [java][org.gradle.api.plugins.JavaPluginConvention] project convention.
*/
val Project.`java`: org.gradle.api.plugins.JavaPluginConvention
get() =
convention.getPluginByName("java")
/**
* Retrieves the [checkstyle][org.gradle.api.plugins.quality.CheckstyleExtension] project extension.
*/
val Project.`checkstyle`: org.gradle.api.plugins.quality.CheckstyleExtension
get() =
extensions.getByName("checkstyle") as org.gradle.api.plugins.quality.CheckstyleExtension
/**
* Configures the [checkstyle][org.gradle.api.plugins.quality.CheckstyleExtension] project extension.
*/
fun Project.`checkstyle`(configure: org.gradle.api.plugins.quality.CheckstyleExtension.() -> Unit) =
extensions.configure("checkstyle", configure)
/**
* Retrieves the [pmd][org.gradle.api.plugins.quality.PmdExtension] project extension.
*/
val Project.`pmd`: org.gradle.api.plugins.quality.PmdExtension
get() =
extensions.getByName("pmd") as org.gradle.api.plugins.quality.PmdExtension
/**
* Configures the [pmd][org.gradle.api.plugins.quality.PmdExtension] project extension.
*/
fun Project.`pmd`(configure: org.gradle.api.plugins.quality.PmdExtension.() -> Unit) =
extensions.configure("pmd", configure)
val Project.`spotbugs`: SpotBugsExtension
get() =
extensions.getByName("spotbugs") as SpotBugsExtension
fun Project.`spotbugs`(configure: SpotBugsExtension.() -> Unit) =
extensions.configure("spotbugs", configure)