forked from wpilibsuite/shuffleboard
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.gradle.kts
363 lines (330 loc) · 11.9 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
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
import edu.wpi.first.wpilib.versioning.ReleaseType
import org.gradle.api.Project
import org.gradle.api.plugins.quality.FindBugs
import org.gradle.api.publish.maven.MavenPublication
import org.gradle.api.tasks.wrapper.Wrapper
import org.gradle.jvm.tasks.Jar
import org.gradle.testing.jacoco.tasks.JacocoReport
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
import org.ajoberstar.grgit.Grgit
import org.ajoberstar.grgit.exception.GrgitException
import org.ajoberstar.grgit.operation.DescribeOp
import java.time.Instant
buildscript {
repositories {
mavenCentral()
jcenter()
}
dependencies {
classpath("org.junit.platform:junit-platform-gradle-plugin:1.0.0")
classpath("org.ajoberstar:grgit:1.7.2")
}
}
plugins {
`maven-publish`
jacoco
id("edu.wpi.first.wpilib.versioning.WPILibVersioningPlugin") version "2.0"
id("com.github.johnrengelman.shadow") version "2.0.1"
id("com.diffplug.gradle.spotless") version "3.5.1"
id("org.ajoberstar.grgit") version "1.7.2"
}
allprojects {
apply {
plugin("com.diffplug.gradle.spotless")
}
getWPILibVersion()?.let { version = it }
// Spotless is used to lint and reformat source files.
spotless {
kotlinGradle {
// Configure the formatting of the Gradle Kotlin DSL files (*.gradle.kts)
ktlint("0.9.1")
endWithNewline()
}
freshmark {
trimTrailingWhitespace()
indentWithSpaces()
endWithNewline()
}
format("extraneous") {
target("Dockerfile", "*.sh", "*.yml")
trimTrailingWhitespace()
indentWithSpaces()
endWithNewline()
}
}
}
allprojects {
apply {
plugin("java")
plugin("checkstyle")
plugin("pmd")
plugin("findbugs")
plugin("jacoco")
plugin("maven-publish")
plugin("org.junit.platform.gradle.plugin")
plugin("edu.wpi.first.wpilib.versioning.WPILibVersioningPlugin")
}
repositories {
mavenCentral()
}
dependencies {
fun junitJupiter(name: String, version: String = "5.0.0") =
create(group = "org.junit.jupiter", name = name, version = version)
"testCompile"(junitJupiter(name = "junit-jupiter-api"))
"testCompile"(junitJupiter(name = "junit-jupiter-engine"))
"testCompile"(junitJupiter(name = "junit-jupiter-params"))
"testRuntime"(create(group = "org.junit.platform", name = "junit-platform-launcher", version = "1.0.0"))
fun testFx(name: String, version: String = "4.0.10-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 = "8u76-b04"))
}
checkstyle {
configFile = file("$rootDir/checkstyle.xml")
toolVersion = "8.1"
}
pmd {
isConsoleOutput = true
sourceSets = setOf(java.sourceSets["main"], java.sourceSets["test"])
reportsDir = file("${project.buildDir}/reports/pmd")
ruleSetFiles = files(file("$rootDir/pmd-ruleset.xml"))
ruleSets = emptyList()
}
findbugs {
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<FindBugs> {
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) }
}
})
}
tasks.withType<JacocoReport> {
reports {
xml.isEnabled = true
html.isEnabled = true
}
}
afterEvaluate {
val junitPlatformTest : JavaExec by tasks
jacoco {
applyTo(junitPlatformTest)
}
task<JacocoReport>("jacocoJunit5TestReport") {
executionData(junitPlatformTest)
sourceSets(java.sourceSets["main"])
sourceDirectories = files(java.sourceSets["main"].allSource.srcDirs)
classDirectories = files(java.sourceSets["main"].output)
}
}
/*
* Run UI tests in headless mode on Jenkins or when the `visibleUiTests` property is not set.
*/
if (project.hasProperty("jenkinsBuild") || !project.hasProperty("visibleUiTests")) {
junitPlatform {
filters {
tags {
/*
* A category for UI tests that cannot run in headless mode, ie work properly with real windows
* but not with the virtualized ones in headless mode.
*/
exclude("NonHeadlessTests")
}
}
}
tasks {
"junitPlatformTest"(JavaExec::class) {
jvmArgs = listOf(
"-Djava.awt.headless=true",
"-Dtestfx.robot=glass",
"-Dtestfx.headless=true",
"-Dprism.order=sw",
"-Dprism.text=t2k"
)
}
}
}
if (project.hasProperty("jenkinsBuild")) {
junitPlatform {
filters {
tags {
exclude("NonJenkinsTest")
}
}
}
}
tasks.withType<Javadoc> {
isFailOnError = false
}
}
project(":app") {
apply {
plugin("com.github.johnrengelman.shadow")
}
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"
}
publishing {
publications {
create<MavenPublication>("app") {
groupId = "edu.wpi.first.shuffleboard"
artifactId = "app"
getWPILibVersion()?.let { version = it }
val shadowJar: ShadowJar by tasks
artifact (shadowJar) {
classifier = null
}
artifact(sourceJar)
artifact(javadocJar)
}
}
}
version = getWPILibVersion() ?: getVersionFromGitTag(fallback = "0.0.0") // fall back to git describe if no WPILib version is set
tasks.withType<Jar> {
manifest {
attributes["Implementation-Version"] = version
attributes["Built-Date"] = Instant.now().toString()
}
}
}
project(":api") {
apply {
plugin("com.github.johnrengelman.shadow")
}
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"
}
publishing {
publications {
create<MavenPublication>("api") {
groupId = "edu.wpi.first.shuffleboard"
artifactId = "api"
getWPILibVersion()?.let { version = it }
afterEvaluate {
from(components["java"])
}
artifact(sourceJar)
artifact(javadocJar)
}
}
}
version = getWPILibVersion() ?: getVersionFromGitTag(fallback = "v0.0.0")
tasks.withType<Jar> {
manifest {
attributes["Implementation-Version"] = version
}
}
}
// Ensure that the WPILibVersioningPlugin is setup by setting the release type, if releaseType wasn't
// already specified on the command line
if (!hasProperty("releaseType")) {
WPILibVersion {
releaseType = ReleaseType.DEV
}
}
/**
* @return [edu.wpi.first.wpilib.versioning.WPILibVersioningPluginExtension.version] value or null
* if that value is the empty string.
*/
fun getWPILibVersion(): String? = if (WPILibVersion.version != "") WPILibVersion.version else null
task<Wrapper>("wrapper") {
gradleVersion = "4.1"
}
/**
* 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)
/**
* Retrieves the [findbugs][org.gradle.api.plugins.quality.FindBugsExtension] project extension.
*/
val Project.`findbugs`: org.gradle.api.plugins.quality.FindBugsExtension get() =
extensions.getByName("findbugs") as org.gradle.api.plugins.quality.FindBugsExtension
/**
* Configures the [findbugs][org.gradle.api.plugins.quality.FindBugsExtension] project extension.
*/
fun Project.`findbugs`(configure: org.gradle.api.plugins.quality.FindBugsExtension.() -> Unit) =
extensions.configure("findbugs", configure)
/**
* Retrieves the [junitPlatform][org.junit.platform.gradle.plugin.JUnitPlatformExtension] project extension.
*/
val Project.`junitPlatform`: org.junit.platform.gradle.plugin.JUnitPlatformExtension get() =
extensions.getByName("junitPlatform") as org.junit.platform.gradle.plugin.JUnitPlatformExtension
/**
* Configures the [junitPlatform][org.junit.platform.gradle.plugin.JUnitPlatformExtension] project extension.
*/
fun Project.`junitPlatform`(configure: org.junit.platform.gradle.plugin.JUnitPlatformExtension.() -> Unit) =
extensions.configure("junitPlatform", configure)
/**
* Gets the build version from git-describe. This is a combination of the most recent tag, the number of commits since
* that tag, and the abbreviated hash of the most recent commit, in this format: `<tag>-<n>-<hash>`; for example,
* v1.0.0-11-9ab123f when the most recent tag is `"v1.0.0"`, with 11 commits since that tag, and the most recent commit
* hash starting with `9ab123f`.
*
* @param fallback the version string to fall back to if git-describe fails. Default value is `"v0.0.0"`.
*
* @see <a href="https://git-scm.com/docs/git-describe">git-describe documentation</a>
*/
fun getVersionFromGitTag(fallback: String = "v0.0.0"): String = try {
val git = Grgit.open()
DescribeOp(git.repository).call()
} catch (e: GrgitException) {
logger.log(LogLevel.WARN, "Cannot get the version from git-describe, falling back to $fallback", e)
fallback
}