|
| 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("mongodb-driver-kotlin-coroutine") |
| 35 | + |
| 36 | +description = "The MongoDB Kotlin Coroutine Driver" |
| 37 | + |
| 38 | +ext.set("pomName", "MongoDB Kotlin Coroutine Driver") |
| 39 | + |
| 40 | +sourceSets { |
| 41 | + create("integrationTest") { |
| 42 | + kotlin.srcDir("$projectDir/src/integration/kotlin") |
| 43 | + compileClasspath += sourceSets.main.get().output |
| 44 | + runtimeClasspath += sourceSets.main.get().output |
| 45 | + compileClasspath += project(":driver-sync").sourceSets.test.get().output |
| 46 | + runtimeClasspath += project(":driver-sync").sourceSets.test.get().output |
| 47 | + compileClasspath += project(":driver-core").sourceSets.test.get().output |
| 48 | + runtimeClasspath += project(":driver-core").sourceSets.test.get().output |
| 49 | + compileClasspath += project(":bson").sourceSets.test.get().output |
| 50 | + runtimeClasspath += project(":bson").sourceSets.test.get().output |
| 51 | + } |
| 52 | +} |
| 53 | + |
| 54 | +val integrationTestImplementation: Configuration by |
| 55 | + configurations.getting { extendsFrom(configurations.testImplementation.get()) } |
| 56 | + |
| 57 | +dependencies { |
| 58 | + // Align versions of all Kotlin components |
| 59 | + implementation(platform("org.jetbrains.kotlin:kotlin-bom")) |
| 60 | + implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8") |
| 61 | + |
| 62 | + implementation(platform("org.jetbrains.kotlinx:kotlinx-coroutines-bom:1.6.4")) |
| 63 | + implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core") |
| 64 | + implementation("org.jetbrains.kotlinx:kotlinx-coroutines-reactive") |
| 65 | + |
| 66 | + api(project(path = ":bson", configuration = "default")) |
| 67 | + api(project(path = ":driver-reactive-streams", configuration = "default")) |
| 68 | + |
| 69 | + testImplementation("org.jetbrains.kotlin:kotlin-reflect") |
| 70 | + testImplementation("org.jetbrains.kotlin:kotlin-test-junit") |
| 71 | + testImplementation("org.mockito.kotlin:mockito-kotlin:4.1.0") |
| 72 | + testImplementation("org.mockito:mockito-junit-jupiter:4.11.0") |
| 73 | + testImplementation("org.assertj:assertj-core:3.24.2") |
| 74 | + testImplementation("io.github.classgraph:classgraph:4.8.154") |
| 75 | + |
| 76 | + integrationTestImplementation("org.jetbrains.kotlin:kotlin-test-junit") |
| 77 | + integrationTestImplementation(project(path = ":driver-sync")) |
| 78 | + integrationTestImplementation(project(path = ":driver-core")) |
| 79 | + integrationTestImplementation(project(path = ":bson")) |
| 80 | +} |
| 81 | + |
| 82 | +kotlin { explicitApi() } |
| 83 | + |
| 84 | +tasks.withType<KotlinCompile> { kotlinOptions.jvmTarget = "1.8" } |
| 85 | + |
| 86 | +// =========================== |
| 87 | +// Code Quality checks |
| 88 | +// =========================== |
| 89 | +spotless { |
| 90 | + kotlinGradle { |
| 91 | + ktfmt("0.39").dropboxStyle().configure { it.setMaxWidth(120) } |
| 92 | + trimTrailingWhitespace() |
| 93 | + indentWithSpaces() |
| 94 | + endWithNewline() |
| 95 | + licenseHeaderFile(rootProject.file("config/mongodb.license"), "(group|plugins|import|buildscript|rootProject)") |
| 96 | + } |
| 97 | + |
| 98 | + kotlin { |
| 99 | + target("**/*.kt") |
| 100 | + ktfmt().dropboxStyle().configure { it.setMaxWidth(120) } |
| 101 | + trimTrailingWhitespace() |
| 102 | + indentWithSpaces() |
| 103 | + endWithNewline() |
| 104 | + licenseHeaderFile(rootProject.file("config/mongodb.license")) |
| 105 | + } |
| 106 | + |
| 107 | + format("extraneous") { |
| 108 | + target("*.xml", "*.yml", "*.md") |
| 109 | + trimTrailingWhitespace() |
| 110 | + indentWithSpaces() |
| 111 | + endWithNewline() |
| 112 | + } |
| 113 | +} |
| 114 | + |
| 115 | +tasks.named("check") { dependsOn("spotlessApply") } |
| 116 | + |
| 117 | +detekt { |
| 118 | + allRules = true // fail build on any finding |
| 119 | + buildUponDefaultConfig = true // preconfigure defaults |
| 120 | + config = rootProject.files("config/detekt/detekt.yml") // point to your custom config defining rules to run, |
| 121 | + // overwriting default behavior |
| 122 | + baseline = rootProject.file("config/detekt/baseline.xml") // a way of suppressing issues before introducing detekt |
| 123 | + source = |
| 124 | + files( |
| 125 | + file("src/main/kotlin"), |
| 126 | + file("src/test/kotlin"), |
| 127 | + file("src/integrationTest/kotlin"), |
| 128 | + ) |
| 129 | +} |
| 130 | + |
| 131 | +tasks.withType<Detekt>().configureEach { |
| 132 | + reports { |
| 133 | + html.required.set(true) // observe findings in your browser with structure and code snippets |
| 134 | + xml.required.set(true) // checkstyle like format mainly for integrations like Jenkins |
| 135 | + txt.required.set(false) // similar to the console output, contains issue signature to manually edit |
| 136 | + } |
| 137 | +} |
| 138 | + |
| 139 | +spotbugs { |
| 140 | + showProgress.set(true) |
| 141 | + |
| 142 | + tasks.getByName("spotbugsIntegrationTest") { enabled = false } |
| 143 | +} |
| 144 | + |
| 145 | +// =========================== |
| 146 | +// Test Configuration |
| 147 | +// =========================== |
| 148 | +val integrationTest = |
| 149 | + tasks.create("integrationTest", Test::class) { |
| 150 | + description = "Runs the integration tests." |
| 151 | + group = "verification" |
| 152 | + |
| 153 | + testClassesDirs = sourceSets["integrationTest"].output.classesDirs |
| 154 | + classpath = sourceSets["integrationTest"].runtimeClasspath |
| 155 | + } |
| 156 | + |
| 157 | +tasks.create("kCheck") { |
| 158 | + description = "Runs all the kotlin checks" |
| 159 | + group = "verification" |
| 160 | + |
| 161 | + dependsOn("clean", "check", integrationTest) |
| 162 | + tasks.findByName("check")?.mustRunAfter("clean") |
| 163 | + tasks.findByName("integrationTest")?.mustRunAfter("check") |
| 164 | +} |
| 165 | + |
| 166 | +tasks.test { useJUnitPlatform() } |
| 167 | + |
| 168 | +// =========================== |
| 169 | +// Dokka Configuration |
| 170 | +// =========================== |
| 171 | +val dokkaOutputDir = "${rootProject.buildDir}/docs/${base.archivesName.get()}" |
| 172 | + |
| 173 | +tasks.dokkaHtml.configure { |
| 174 | + outputDirectory.set(file(dokkaOutputDir)) |
| 175 | + moduleName.set(base.archivesName.get()) |
| 176 | +} |
| 177 | + |
| 178 | +val cleanDokka by tasks.register<Delete>("cleanDokka") { delete(dokkaOutputDir) } |
| 179 | + |
| 180 | +project.parent?.tasks?.named("docs") { |
| 181 | + dependsOn(tasks.dokkaHtml) |
| 182 | + mustRunAfter(cleanDokka) |
| 183 | +} |
| 184 | + |
| 185 | +tasks.javadocJar.configure { |
| 186 | + dependsOn(cleanDokka, tasks.dokkaHtml) |
| 187 | + archiveClassifier.set("javadoc") |
| 188 | + from(dokkaOutputDir) |
| 189 | +} |
0 commit comments