forked from wpilibsuite/PathWeaver
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbuild.gradle.kts
248 lines (214 loc) · 7.07 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
import edu.wpi.first.wpilib.versioning.ReleaseType
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 com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
buildscript {
repositories {
mavenCentral()
jcenter()
}
}
plugins {
`maven-publish`
jacoco
java
checkstyle
application
pmd
id("edu.wpi.first.wpilib.versioning.WPILibVersioningPlugin") version "2.2"
id("com.github.johnrengelman.shadow") version "2.0.1"
id("com.diffplug.gradle.spotless") version "3.13.0"
}
// 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
}
}
version = getWPILibVersion()
val theMainClassName = "edu.wpi.first.pathweaver.Main"
tasks.withType<Jar>().configureEach {
manifest {
attributes["Implementation-Version"] = project.version as String
attributes["Built-Date"] = Instant.now().toString()
attributes["Main-Class"] = theMainClassName
}
}
application {
mainClassName = theMainClassName
}
repositories {
mavenCentral()
}
// Spotless is used to lint and reformat source files.
spotless {
kotlinGradle {
ktlint("0.24.0")
trimTrailingWhitespace()
indentWithSpaces()
endWithNewline()
}
format("extraneous") {
target("Dockerfile", "*.sh", "*.yml")
trimTrailingWhitespace()
indentWithSpaces()
endWithNewline()
}
}
createNativeConfigurations()
dependencies {
// JavaFX dependencies
javafx("base")
javafx("controls")
javafx("fxml")
javafx("graphics")
compile("org.apache.commons", "commons-csv", "1.5")
compile("javax.measure", "unit-api", "1.0")
compile("si.uom", "si-units", "0.9")
compile("systems.uom", "systems-common", "0.8")
compile("com.google.code.gson", "gson", "2.8.5")
fun junitJupiter(name: String, version: String = "5.2.0") =
create(group = "org.junit.jupiter", name = name, version = version)
fun testFx(name: String, version: String = "4.0.13-alpha") =
create(group = "org.testfx", name = name, version = version)
testCompile(junitJupiter(name = "junit-jupiter-api"))
testCompile(junitJupiter(name = "junit-jupiter-engine"))
testCompile(junitJupiter(name = "junit-jupiter-params"))
testCompile(group = "com.google.guava", name = "guava-testlib", version = "23.0")
testCompile(testFx(name = "testfx-core"))
testCompile(testFx(name = "testfx-junit5"))
testRuntime(testFx(name = "openjfx-monocle", version = "jdk-9+181"))
testRuntime(group = "org.junit.platform", name = "junit-platform-launcher", version = "1.0.0")
}
checkstyle {
toolVersion = "8.12"
}
pmd {
toolVersion = "6.8.0"
isConsoleOutput = true
reportsDir = file("${project.buildDir}/reports/pmd")
ruleSetFiles = files(file("$rootDir/pmd-ruleset.xml"))
ruleSets = emptyList()
}
tasks.withType<JavaCompile>().configureEach {
// UTF-8 characters are used in menus
options.encoding = "UTF-8"
options.compilerArgs.add("-Xlint:unchecked")
options.compilerArgs.add("-Xlint:deprecation")
}
jacoco {
toolVersion = "0.8.2"
}
tasks.withType<JacocoReport>().configureEach {
reports {
xml.isEnabled = true
html.isEnabled = true
}
}
tasks.withType<Test>().configureEach {
// 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>().configureEach {
isFailOnError = false
}
val nativeShadowTasks = NativePlatforms.values().map { platform ->
tasks.create<ShadowJar>("shadowJar-${platform.platformName}") {
classifier = platform.platformName
configurations = listOf(
project.configurations.compile,
project.configurations.getByName(platform.platformName)
)
from(
java.sourceSets["main"].output
)
}
}
tasks.create("shadowJarAllPlatforms") {
nativeShadowTasks.forEach {
this.dependsOn(it)
}
}
tasks.withType<ShadowJar>().configureEach {
exclude("module-info.class")
}
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.wpilib"
artifactId = "PathWeaver"
version = project.version as String
nativeShadowTasks.forEach {
artifact(it) {
classifier = it.classifier
}
}
}
}
}
/**
* @return publishVersion property if exists, otherwise
* [edu.wpi.first.wpilib.versioning.WPILibVersioningPluginExtension.version] value or fallback
* if that value is the empty string.
*/
fun getWPILibVersion(fallback: String = "v0.0.0"): String {
if (project.hasProperty("publishVersion")) {
val publishVersion: String by project
return publishVersion
} else if (WPILibVersion.version != "") {
return WPILibVersion.version
} else {
return fallback
}
}
tasks.withType<Wrapper>().configureEach {
gradleVersion = "4.9"
}
/**
* 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)