forked from oss-review-toolkit/ort
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.gradle.kts
376 lines (299 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
364
365
366
367
368
369
370
371
372
373
374
375
376
/*
* Copyright (C) 2017-2019 HERE Europe B.V.
* Copyright (C) 2019 Bosch Software Innovations GmbH
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* SPDX-License-Identifier: Apache-2.0
* License-Filename: LICENSE
*/
import com.github.benmanes.gradle.versions.updates.DependencyUpdatesTask
import com.here.ort.gradle.*
import io.gitlab.arturbosch.detekt.Detekt
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 jacksonVersion: String by project
val kotlintestVersion: String by project
val log4jCoreVersion: String by project
val okhttpVersion: String by project
plugins {
kotlin("jvm")
id("io.gitlab.arturbosch.detekt")
id("org.jetbrains.dokka")
id("com.github.ben-manes.versions")
id("org.ajoberstar.reckon")
id("org.jetbrains.gradle.plugin.idea-ext")
}
reckon {
scopeFromProp()
snapshotFromProp()
}
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"
fun isNonFinalVersion(version: String): Boolean {
val nonFinalQualifiers = listOf(
"alpha", "b", "beta", "cr", "ea", "eap", "m", "milestone", "pr", "preview", "rc"
)
return nonFinalQualifiers.any { qualifier ->
version.matches(Regex("(?i).*[.-]$qualifier[.\\d-+]*"))
}
}
rejectVersionIf {
isNonFinalVersion(candidate.version)
}
}
allprojects {
buildscript {
repositories {
jcenter()
}
}
repositories {
jcenter()
}
apply(plugin = "io.gitlab.arturbosch.detekt")
// 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"(project(":detekt-rules"))
"detektPlugins"("io.gitlab.arturbosch.detekt:detekt-formatting:$detektPluginVersion")
}
detekt {
// Align the detekt core and plugin versions.
toolVersion = detektPluginVersion
// Only configure differences to the default.
buildUponDefaultConfig = true
config = files("$rootDir/.detekt.yml")
input = files("$rootDir/buildSrc", "build.gradle.kts", "src/main/kotlin", "src/test/kotlin",
"src/funTest/kotlin")
}
tasks.withType<Detekt> {
dependsOn(":detekt-rules:assemble")
}
}
subprojects {
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")
// 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")
}
}
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 all OkHttp versions in use match our version >= 4 to avoid Kotlin vs. Java issues with OkHttp 3.
force("com.squareup.okhttp3:okhttp:$okhttpVersion")
// Ensure all API library versions match our core library version.
force("org.apache.logging.log4j:log4j-api:$log4jCoreVersion")
// 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"
}
}
tasks.named<DokkaTask>("dokka") {
configuration {
jdkVersion = 8
externalDocumentationLink {
val baseUrl = "https://codehaus-plexus.github.io/plexus-containers/plexus-container-default/apidocs"
url = URL(baseUrl)
packageListUrl = URL("$baseUrl/package-list")
}
externalDocumentationLink {
val majorMinorVersion = jacksonVersion.split('.').let { "${it[0]}.${it[1]}" }
val baseUrl = "https://fasterxml.github.io/jackson-databind/javadoc/$majorMinorVersion"
url = URL(baseUrl)
packageListUrl = URL("$baseUrl/package-list")
}
externalDocumentationLink {
val baseUrl = "https://jakewharton.github.io/DiskLruCache"
url = URL(baseUrl)
packageListUrl = URL("$baseUrl/package-list")
}
externalDocumentationLink {
val majorVersion = log4jCoreVersion.split('.').first()
val baseUrl = "https://logging.apache.org/log4j/$majorVersion.x/log4j-api/apidocs"
url = URL(baseUrl)
packageListUrl = URL("$baseUrl/package-list")
}
}
}
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) {
isEnabled = enabled
}
systemProperties = listOf("kotlintest.tags.include", "kotlintest.tags.exclude").associateWith {
System.getProperty(it)
}
testLogging {
events = setOf(TestLogEvent.STARTED, TestLogEvent.PASSED, TestLogEvent.SKIPPED, TestLogEvent.FAILED)
exceptionFormat = TestExceptionFormat.FULL
}
useJUnitPlatform()
}
}
tasks.named<JacocoReport>("jacocoTestReport") {
reports {
// Enable XML in addition to HTML for CI integration.
xml.isEnabled = 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.isEnabled = 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)
}
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:git@github.com:heremaps/oss-review-toolkit.git")
tag.set(version.toString())
url.set("https://github.com/heremaps/oss-review-toolkit")
}
}
}
}
}
}
tasks.register<Exec>("checkCopyright") {
description = "Checks for Copyright headers in Kotlin files."
group = "Verification"
commandLine = listOf("git", "grep", "-EL", "Copyright \\(C\\) .+", "*.kt", "*.kts",
":!analyzer/src/funTest/assets/projects/external")
isIgnoreExitValue = 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("allDependencies") {
val dependenciesTasks = allprojects.map { it.tasks.named("dependencies").get() }
dependsOn(dependenciesTasks)
dependenciesTasks.zipWithNext().forEach { (a, b) ->
b.mustRunAfter(a)
}
}