|
| 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") |
| 21 | + `java-library` |
| 22 | + |
| 23 | + // Test based plugins |
| 24 | + id("com.diffplug.spotless") |
| 25 | + id("org.jetbrains.dokka") |
| 26 | + id("io.gitlab.arturbosch.detekt") |
| 27 | +} |
| 28 | + |
| 29 | +repositories { |
| 30 | + mavenCentral() |
| 31 | + google() |
| 32 | +} |
| 33 | + |
| 34 | +base.archivesName.set("mongodb-driver-kotlin-extensions") |
| 35 | + |
| 36 | +description = "The MongoDB Kotlin Driver Extensions" |
| 37 | + |
| 38 | +ext.set("pomName", "MongoDB Kotlin Driver Extensions") |
| 39 | + |
| 40 | +java { registerFeature("kotlinDrivers") { usingSourceSet(sourceSets["main"]) } } |
| 41 | + |
| 42 | +dependencies { |
| 43 | + // Align versions of all Kotlin components |
| 44 | + implementation(platform("org.jetbrains.kotlin:kotlin-bom")) |
| 45 | + implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8") |
| 46 | + |
| 47 | + api(project(path = ":driver-core", configuration = "default")) |
| 48 | + |
| 49 | + // Some extensions require higher API like MongoCollection which are defined in the sync & |
| 50 | + // coroutine Kotlin driver |
| 51 | + "kotlinDriversImplementation"(project(path = ":driver-kotlin-sync", configuration = "default")) |
| 52 | + "kotlinDriversImplementation"(project(path = ":driver-kotlin-coroutine", configuration = "default")) |
| 53 | + |
| 54 | + testImplementation("org.jetbrains.kotlin:kotlin-reflect") |
| 55 | + testImplementation("org.jetbrains.kotlin:kotlin-test-junit") |
| 56 | + testImplementation("org.assertj:assertj-core:3.24.2") |
| 57 | + testImplementation("io.github.classgraph:classgraph:4.8.154") |
| 58 | + testImplementation("org.mockito.kotlin:mockito-kotlin:4.1.0") |
| 59 | +} |
| 60 | + |
| 61 | +kotlin { explicitApi() } |
| 62 | + |
| 63 | +tasks.withType<KotlinCompile> { |
| 64 | + kotlinOptions { |
| 65 | + jvmTarget = "1.8" |
| 66 | + freeCompilerArgs = |
| 67 | + listOf( |
| 68 | + // Adds OnlyInputTypes support |
| 69 | + "-Xallow-kotlin-package", |
| 70 | + ) |
| 71 | + } |
| 72 | +} |
| 73 | + |
| 74 | +// =========================== |
| 75 | +// Code Quality checks |
| 76 | +// =========================== |
| 77 | +val customLicenseHeader = "/^(?s)(?!.*@custom-license-header).*/" |
| 78 | + |
| 79 | +spotless { |
| 80 | + kotlinGradle { |
| 81 | + ktfmt("0.39").dropboxStyle().configure { it.setMaxWidth(120) } |
| 82 | + trimTrailingWhitespace() |
| 83 | + indentWithSpaces() |
| 84 | + endWithNewline() |
| 85 | + licenseHeaderFile(rootProject.file("config/mongodb.license"), "(group|plugins|import|buildscript|rootProject)") |
| 86 | + } |
| 87 | + |
| 88 | + kotlin { |
| 89 | + target("**/*.kt") |
| 90 | + ktfmt().dropboxStyle().configure { it.setMaxWidth(120) } |
| 91 | + trimTrailingWhitespace() |
| 92 | + indentWithSpaces() |
| 93 | + endWithNewline() |
| 94 | + |
| 95 | + licenseHeaderFile(rootProject.file("config/mongodb.license")) |
| 96 | + .named("standard") |
| 97 | + .onlyIfContentMatches(customLicenseHeader) |
| 98 | + } |
| 99 | + |
| 100 | + format("extraneous") { |
| 101 | + target("*.xml", "*.yml", "*.md") |
| 102 | + trimTrailingWhitespace() |
| 103 | + indentWithSpaces() |
| 104 | + endWithNewline() |
| 105 | + } |
| 106 | +} |
| 107 | + |
| 108 | +tasks.named("check") { dependsOn("spotlessApply") } |
| 109 | + |
| 110 | +detekt { |
| 111 | + allRules = true // fail build on any finding |
| 112 | + buildUponDefaultConfig = true // preconfigure defaults |
| 113 | + config = rootProject.files("config/detekt/detekt.yml") // point to your custom config defining rules to run, |
| 114 | + // overwriting default behavior |
| 115 | + baseline = rootProject.file("config/detekt/baseline.xml") // a way of suppressing issues before introducing detekt |
| 116 | + source = files(file("src/main/kotlin"), file("src/test/kotlin")) |
| 117 | +} |
| 118 | + |
| 119 | +tasks.withType<Detekt>().configureEach { |
| 120 | + reports { |
| 121 | + html.required.set(true) // observe findings in your browser with structure and code snippets |
| 122 | + xml.required.set(true) // checkstyle like format mainly for integrations like Jenkins |
| 123 | + txt.required.set(false) // similar to the console output, contains issue signature to manually edit |
| 124 | + } |
| 125 | +} |
| 126 | + |
| 127 | +spotbugs { showProgress.set(true) } |
| 128 | + |
| 129 | +tasks.spotbugsMain { |
| 130 | + // we need the xml report to find out the "rank" (see config/spotbugs/exclude.xml) |
| 131 | + reports.getByName("xml") { required.set(true) } |
| 132 | +} |
| 133 | + |
| 134 | +// =========================== |
| 135 | +// Test Configuration |
| 136 | +// =========================== |
| 137 | + |
| 138 | +tasks.test { useJUnitPlatform() } |
| 139 | + |
| 140 | +// =========================== |
| 141 | +// Dokka Configuration |
| 142 | +// =========================== |
| 143 | +val dokkaOutputDir = "${rootProject.buildDir}/docs/${base.archivesName.get()}" |
| 144 | + |
| 145 | +tasks.dokkaHtml.configure { |
| 146 | + outputDirectory.set(file(dokkaOutputDir)) |
| 147 | + moduleName.set(base.archivesName.get()) |
| 148 | +} |
| 149 | + |
| 150 | +val cleanDokka by tasks.register<Delete>("cleanDokka") { delete(dokkaOutputDir) } |
| 151 | + |
| 152 | +project.parent?.tasks?.named("docs") { |
| 153 | + dependsOn(tasks.dokkaHtml) |
| 154 | + mustRunAfter(cleanDokka) |
| 155 | +} |
| 156 | + |
| 157 | +tasks.javadocJar.configure { |
| 158 | + dependsOn(cleanDokka, tasks.dokkaHtml) |
| 159 | + archiveClassifier.set("javadoc") |
| 160 | + from(dokkaOutputDir) |
| 161 | +} |
| 162 | + |
| 163 | +// =========================== |
| 164 | +// Sources publishing configuration |
| 165 | +// =========================== |
| 166 | +tasks.sourcesJar { from(project.sourceSets.main.map { it.kotlin }) } |
| 167 | + |
| 168 | +afterEvaluate { tasks.jar { manifest { attributes["Automatic-Module-Name"] = "org.mongodb.driver.kotlin.core" } } } |
0 commit comments