-
Notifications
You must be signed in to change notification settings - Fork 1.5k
/
Copy pathbuild.gradle.kts
145 lines (118 loc) · 4.35 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
/*
* Copyright 2008-present MongoDB, Inc.
*
* 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.
*/
import io.gitlab.arturbosch.detekt.Detekt
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
plugins {
id("org.jetbrains.kotlin.jvm")
`java-library`
// Test based plugins
id("com.diffplug.spotless")
id("org.jetbrains.dokka")
id("io.gitlab.arturbosch.detekt")
}
repositories {
mavenCentral()
google()
}
base.archivesName.set("bson-kotlin")
description = "Bson Kotlin Codecs"
ext.set("pomName", "Bson Kotlin")
dependencies {
// Align versions of all Kotlin components
implementation(platform("org.jetbrains.kotlin:kotlin-bom"))
implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8")
api(project(path = ":bson", configuration = "default"))
implementation("org.jetbrains.kotlin:kotlin-reflect")
testImplementation("org.jetbrains.kotlin:kotlin-test-junit")
testImplementation(project(path = ":driver-core", configuration = "default"))
}
kotlin { explicitApi() }
tasks.withType<KotlinCompile> { kotlinOptions.jvmTarget = "1.8" }
// ===========================
// Code Quality checks
// ===========================
spotless {
kotlinGradle {
ktfmt("0.39").dropboxStyle().configure { it.setMaxWidth(120) }
trimTrailingWhitespace()
indentWithSpaces()
endWithNewline()
licenseHeaderFile(rootProject.file("config/mongodb.license"), "(group|plugins|import|buildscript|rootProject)")
}
kotlin {
target("**/*.kt")
ktfmt().dropboxStyle().configure { it.setMaxWidth(120) }
trimTrailingWhitespace()
indentWithSpaces()
endWithNewline()
licenseHeaderFile(rootProject.file("config/mongodb.license"))
}
format("extraneous") {
target("*.xml", "*.yml", "*.md")
trimTrailingWhitespace()
indentWithSpaces()
endWithNewline()
}
}
tasks.named("check") { dependsOn("spotlessApply") }
detekt {
allRules = true // fail build on any finding
buildUponDefaultConfig = true // preconfigure defaults
config = rootProject.files("config/detekt/detekt.yml") // point to your custom config defining rules to run,
// overwriting default behavior
baseline = rootProject.file("config/detekt/baseline.xml") // a way of suppressing issues before introducing detekt
source =
files(
file("src/main/kotlin"),
file("src/test/kotlin"),
file("src/integrationTest/kotlin"),
)
}
tasks.withType<Detekt>().configureEach {
reports {
html.required.set(true) // observe findings in your browser with structure and code snippets
xml.required.set(true) // checkstyle like format mainly for integrations like Jenkins
txt.required.set(false) // similar to the console output, contains issue signature to manually edit
}
}
spotbugs { showProgress.set(true) }
// ===========================
// Test Configuration
// ===========================
tasks.test { useJUnitPlatform() }
// ===========================
// Dokka Configuration
// ===========================
val dokkaOutputDir = "${rootProject.buildDir}/docs/${base.archivesName.get()}"
tasks.dokkaHtml.configure {
outputDirectory.set(file(dokkaOutputDir))
moduleName.set(base.archivesName.get())
}
val cleanDokka by tasks.register<Delete>("cleanDokka") { delete(dokkaOutputDir) }
project.parent?.tasks?.named("docs") {
dependsOn(tasks.dokkaHtml)
mustRunAfter(cleanDokka)
}
tasks.javadocJar.configure {
dependsOn(cleanDokka, tasks.dokkaHtml)
archiveClassifier.set("javadoc")
from(dokkaOutputDir)
}
// ===========================
// Sources publishing configuration
// ===========================
tasks.sourcesJar { from(project.sourceSets.main.map { it.kotlin }) }
afterEvaluate { tasks.jar { manifest { attributes["Automatic-Module-Name"] = "org.mongodb.bson.kotlin" } } }