forked from oss-review-toolkit/ort
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.gradle.kts
324 lines (252 loc) · 9.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
import com.github.benmanes.gradle.versions.updates.DependencyUpdatesTask
import com.here.ort.gradle.*
import io.gitlab.arturbosch.detekt.detekt
import org.ajoberstar.grgit.Grgit
import org.gradle.api.tasks.testing.logging.TestExceptionFormat
import org.gradle.api.tasks.testing.logging.TestLogEvent
import org.jetbrains.dokka.gradle.DokkaTask
import org.jetbrains.gradle.ext.JUnit
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
import org.jetbrains.kotlin.gradle.plugin.KotlinSourceSet
import java.io.ByteArrayOutputStream
import java.net.URL
val detektPluginVersion: String by project
val kotlinPluginVersion: String by project
val kotlintestVersion: String by project
plugins {
kotlin("jvm") apply false
id("io.gitlab.arturbosch.detekt") apply false
id("org.jetbrains.dokka") apply false
id("com.github.ben-manes.versions")
id("org.ajoberstar.grgit")
id("org.jetbrains.gradle.plugin.idea-ext")
}
idea {
project {
settings {
runConfigurations {
defaults<JUnit> {
// Disable "condensed" multi-line diffs when running tests from the IDE to more easily accept actual results
// as expected results.
vmParameters = "-Dkotlintest.assertions.multi-line-diff=simple"
}
}
}
}
}
extensions.findByName("buildScan")?.withGroovyBuilder {
setProperty("termsOfServiceUrl", "https://gradle.com/terms-of-service")
setProperty("termsOfServiceAgree", "yes")
}
tasks.named<DependencyUpdatesTask>("dependencyUpdates") {
gradleReleaseChannel = "current"
resolutionStrategy {
componentSelection {
all {
val isNonFinalVersion = listOf("alpha", "beta", "rc", "cr", "m", "preview", "b", "ea").any { qualifier ->
candidate.version.matches(Regex("(?i).*[.-]$qualifier[.\\d-+]*"))
}
if (isNonFinalVersion) reject("Release candidate")
}
}
}
}
subprojects {
buildscript {
repositories {
jcenter()
}
}
if (name == "reporter-web-app") return@subprojects
// Apply core plugins.
apply(plugin = "jacoco")
apply(plugin = "maven-publish")
// Apply third-party plugins.
apply(plugin = "org.jetbrains.kotlin.jvm")
apply(plugin = "org.jetbrains.dokka")
apply(plugin = "io.gitlab.arturbosch.detekt")
// Note: Kotlin DSL cannot directly access sourceSets that are created by applying a plugin in the very same
// project, thus get the source set programmatically.
val sourceSets = the<SourceSetContainer>()
sourceSets.create("funTest") {
withConvention(KotlinSourceSet::class) {
kotlin.srcDirs("src/funTest/kotlin")
}
}
repositories {
jcenter()
}
// Note: Kotlin DSL cannot directly access configurations that are created by applying a plugin in the very same
// project, thus put configuration names in quotes to leverage lazy lookup.
dependencies {
"detektPlugins"("io.gitlab.arturbosch.detekt:detekt-formatting:$detektPluginVersion")
}
plugins.withType<JavaLibraryPlugin> {
dependencies {
"api"("org.jetbrains.kotlin:kotlin-stdlib-jdk8")
"testImplementation"("io.kotlintest:kotlintest-core:$kotlintestVersion")
"testImplementation"("io.kotlintest:kotlintest-assertions:$kotlintestVersion")
"testImplementation"("io.kotlintest:kotlintest-runner-junit5:$kotlintestVersion")
"testImplementation"(project(":test-utils"))
"funTestImplementation"(sourceSets["main"].output)
}
configurations["funTestImplementation"].extendsFrom(configurations["testImplementation"])
}
configurations.all {
resolutionStrategy {
// Ensure that all transitive versions of "kotlin-reflect" match our version of "kotlin-stdlib".
force("org.jetbrains.kotlin:kotlin-reflect:$kotlinPluginVersion")
}
}
tasks.withType<KotlinCompile>().configureEach {
kotlinOptions {
allWarningsAsErrors = true
jvmTarget = "1.8"
apiVersion = "1.3"
}
}
detekt {
// Align the detekt core and plugin versions.
toolVersion = detektPluginVersion
config = files("../.detekt.yml")
input = files("src/main/kotlin", "src/test/kotlin", "src/funTest/kotlin")
}
tasks.named<DokkaTask>("dokka") {
jdkVersion = 8
externalDocumentationLink {
url = URL("https://codehaus-plexus.github.io/plexus-containers/plexus-container-default/apidocs/")
}
externalDocumentationLink {
url = URL("https://fasterxml.github.io/jackson-databind/javadoc/2.9/")
}
externalDocumentationLink {
url = URL("http://jakewharton.github.io/DiskLruCache/")
}
externalDocumentationLink {
url = URL("https://logback.qos.ch/apidocs/")
}
}
val funTest by tasks.registering(Test::class) {
description = "Runs the functional tests."
group = "Verification"
classpath = sourceSets["funTest"].runtimeClasspath
testClassesDirs = sourceSets["funTest"].output.classesDirs
}
// Enable JaCoCo only if a JacocoReport task is in the graph as JaCoCo
// is using "append = true" which disables Gradle's build cache.
gradle.taskGraph.whenReady {
val enabled = allTasks.any { it is JacocoReport }
tasks.withType<Test>().configureEach {
extensions.configure(JacocoTaskExtension::class) {
setEnabled(enabled)
}
systemProperties = listOf("kotlintest.tags.include", "kotlintest.tags.exclude").associateWith {
System.getProperty(it)
}
testLogging {
events = setOf(TestLogEvent.STARTED, TestLogEvent.PASSED, TestLogEvent.SKIPPED, TestLogEvent.FAILED)
setExceptionFormat(TestExceptionFormat.FULL)
}
useJUnitPlatform()
}
}
tasks.named<JacocoReport>("jacocoTestReport") {
reports {
// Enable XML in addition to HTML for CI integration.
xml.setEnabled(true)
}
}
tasks.register<JacocoReport>("jacocoFunTestReport") {
description = "Generates code coverage report for the funTest task."
group = "Reporting"
executionData(funTest.get())
sourceSets(sourceSets["main"])
reports {
// Enable XML in addition to HTML for CI integration.
xml.setEnabled(true)
}
}
tasks.register("jacocoReport") {
description = "Generates code coverage reports for all test tasks."
group = "Reporting"
dependsOn(tasks.withType<JacocoReport>())
}
tasks.named("check") {
dependsOn(funTest)
}
val sourcesJar by tasks.registering(Jar::class) {
archiveClassifier.set("sources")
from(sourceSets["main"].allSource)
}
val dokka by tasks.existing(DokkaTask::class) {
description = "Generates minimalistic HTML documentation, Java classes are translated to Kotlin."
}
val dokkaJar by tasks.registering(Jar::class) {
dependsOn(dokka)
description = "Assembles a jar archive containing the minimalistic HTML documentation."
group = "Documentation"
archiveClassifier.set("dokka")
from(dokka.get().outputDirectory)
}
val dokkaJavadoc by tasks.registering(DokkaTask::class) {
description = "Generates documentation that looks like normal Javadoc, Kotlin classes are translated to Java."
outputFormat = "javadoc"
outputDirectory = "$buildDir/javadoc"
}
val javadocJar by tasks.registering(Jar::class) {
dependsOn(dokkaJavadoc)
description = "Assembles a jar archive containing the Javadoc documentation."
group = "Documentation"
archiveClassifier.set("javadoc")
from(dokkaJavadoc.get().outputDirectory)
}
version = object : Object() {
private val git = Grgit.open(mapOf("dir" to rootDir))
override fun toString(): String {
return git.describe(mapOf("longDescr" to true, "tags" to true)) ?: git.head().abbreviatedId
}
}
configure<PublishingExtension> {
publications {
create<MavenPublication>(name) {
groupId = "com.here.ort"
from(components["java"])
artifact(sourcesJar.get())
artifact(javadocJar.get())
pom {
licenses {
license {
name.set("Apache-2.0")
url.set("http://www.apache.org/licenses/LICENSE-2.0")
}
}
scm {
connection.set("scm:git:https://github.com/heremaps/oss-review-toolkit.git")
developerConnection.set("scm:git:[email protected]:heremaps/oss-review-toolkit.git")
tag.set(version.toString())
url.set("https://github.com/heremaps/oss-review-toolkit")
}
}
}
}
}
}
val checkCopyright by tasks.registering(Exec::class) {
description = "Checks for HERE Copyright headers in Kotlin files."
group = "Verification"
commandLine = listOf("git", "grep", "-EL", "Copyright \\(C\\) .+", "*.kt",
":!analyzer/src/funTest/assets/projects/external")
setIgnoreExitValue(true)
standardOutput = ByteArrayOutputStream()
doLast {
val output = standardOutput.toString().trim()
if (output.isNotEmpty()) {
throw GradleException("Please add copyright statements to the following Kotlin files:\n$output")
}
}
}
tasks.register("check") {
description = "Runs all checks."
group = "Verification"
dependsOn(checkCopyright)
}