Skip to content

Commit e815dad

Browse files
committed
Bson-kotlin
Library adds Bson support for Kotlin data classes Follows the spirit of the bson-record-codec library JAVA-4872
1 parent c36e7ee commit e815dad

File tree

14 files changed

+1084
-4
lines changed

14 files changed

+1084
-4
lines changed

bson-kotlin/build.gradle.kts

Lines changed: 145 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,145 @@
1+
/*
2+
* Copyright 2008-present MongoDB, Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
import io.gitlab.arturbosch.detekt.Detekt
17+
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
18+
19+
plugins {
20+
id("org.jetbrains.kotlin.jvm") version "1.8.10"
21+
`java-library`
22+
23+
// Test based plugins
24+
id("com.diffplug.spotless")
25+
id("org.jetbrains.dokka") version "1.7.20"
26+
id("io.gitlab.arturbosch.detekt") version "1.21.0"
27+
}
28+
29+
repositories {
30+
mavenCentral()
31+
google()
32+
}
33+
34+
base.archivesName.set("bson-kotlin")
35+
36+
description = "Bson Kotlin Codecs"
37+
38+
ext.set("pomName", "Bson Kotlin")
39+
40+
dependencies {
41+
// Align versions of all Kotlin components
42+
implementation(platform("org.jetbrains.kotlin:kotlin-bom"))
43+
implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8")
44+
45+
api(project(path = ":bson", configuration = "default"))
46+
implementation("org.jetbrains.kotlin:kotlin-reflect")
47+
48+
testImplementation("org.jetbrains.kotlin:kotlin-test-junit")
49+
testImplementation(project(path = ":driver-core", configuration = "default"))
50+
}
51+
52+
kotlin { explicitApi() }
53+
54+
tasks.withType<KotlinCompile> { kotlinOptions.jvmTarget = "1.8" }
55+
56+
// ===========================
57+
// Code Quality checks
58+
// ===========================
59+
spotless {
60+
kotlinGradle {
61+
ktfmt("0.39").dropboxStyle().configure { it.setMaxWidth(120) }
62+
trimTrailingWhitespace()
63+
indentWithSpaces()
64+
endWithNewline()
65+
licenseHeaderFile(rootProject.file("config/mongodb.license"), "(group|plugins|import|buildscript|rootProject)")
66+
}
67+
68+
kotlin {
69+
target("**/*.kt")
70+
ktfmt().dropboxStyle().configure { it.setMaxWidth(120) }
71+
trimTrailingWhitespace()
72+
indentWithSpaces()
73+
endWithNewline()
74+
licenseHeaderFile(rootProject.file("config/mongodb.license"))
75+
}
76+
77+
format("extraneous") {
78+
target("*.xml", "*.yml", "*.md")
79+
trimTrailingWhitespace()
80+
indentWithSpaces()
81+
endWithNewline()
82+
}
83+
}
84+
85+
tasks.named("check") { dependsOn("spotlessApply") }
86+
87+
detekt {
88+
allRules = true // fail build on any finding
89+
buildUponDefaultConfig = true // preconfigure defaults
90+
config = rootProject.files("config/detekt/detekt.yml") // point to your custom config defining rules to run,
91+
// overwriting default behavior
92+
baseline = rootProject.file("config/detekt/baseline.xml") // a way of suppressing issues before introducing detekt
93+
source =
94+
files(
95+
file("src/main/kotlin"),
96+
file("src/test/kotlin"),
97+
file("src/integrationTest/kotlin"),
98+
)
99+
}
100+
101+
tasks.withType<Detekt>().configureEach {
102+
reports {
103+
html.required.set(true) // observe findings in your browser with structure and code snippets
104+
xml.required.set(true) // checkstyle like format mainly for integrations like Jenkins
105+
txt.required.set(false) // similar to the console output, contains issue signature to manually edit
106+
}
107+
}
108+
109+
spotbugs { showProgress.set(true) }
110+
111+
// ===========================
112+
// Test Configuration
113+
// ===========================
114+
tasks.create("kCheck") {
115+
description = "Runs all the kotlin checks"
116+
group = "verification"
117+
118+
dependsOn("clean", "check")
119+
tasks.findByName("check")?.mustRunAfter("clean")
120+
}
121+
122+
tasks.test { useJUnitPlatform() }
123+
124+
// ===========================
125+
// Dokka Configuration
126+
// ===========================
127+
val dokkaOutputDir = "${rootProject.buildDir}/docs/${base.archivesName.get()}"
128+
129+
tasks.dokkaHtml.configure {
130+
outputDirectory.set(file(dokkaOutputDir))
131+
moduleName.set(base.archivesName.get())
132+
}
133+
134+
val cleanDokka by tasks.register<Delete>("cleanDokka") { delete(dokkaOutputDir) }
135+
136+
project.parent?.tasks?.named("docs") {
137+
dependsOn(tasks.dokkaHtml)
138+
mustRunAfter(cleanDokka)
139+
}
140+
141+
tasks.javadocJar.configure {
142+
dependsOn(cleanDokka, tasks.dokkaHtml)
143+
archiveClassifier.set("javadoc")
144+
from(dokkaOutputDir)
145+
}

0 commit comments

Comments
 (0)