-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Helper methods and extensions to improve kotlin interop. #1478
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 4 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
955c538
Helper methods and extensions to improve kotlin interop. Based on kmo…
rozza 5c19eb0
Use a companion object rather than an invalid package name
rozza 3f520a2
Remove temp file
rozza 3a8fc1a
Code review updates
rozza 012f92c
Merge branch 'master' into JAVA-5308
rozza c7272e4
PR updates
rozza a500d9c
Mark jvm methods as synthentic as well
rozza File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,163 @@ | ||
/* | ||
* 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("mongodb-driver-kotlin-extensions") | ||
|
||
description = "The MongoDB Kotlin Driver Extensions" | ||
|
||
ext.set("pomName", "MongoDB Kotlin Driver Extensions") | ||
|
||
dependencies { | ||
// Align versions of all Kotlin components | ||
implementation(platform("org.jetbrains.kotlin:kotlin-bom")) | ||
implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8") | ||
|
||
api(project(path = ":driver-core", configuration = "default")) | ||
|
||
testImplementation("org.jetbrains.kotlin:kotlin-reflect") | ||
testImplementation("org.jetbrains.kotlin:kotlin-test-junit") | ||
testImplementation("org.assertj:assertj-core:3.24.2") | ||
testImplementation("io.github.classgraph:classgraph:4.8.154") | ||
} | ||
|
||
kotlin { explicitApi() } | ||
|
||
tasks.withType<KotlinCompile> { | ||
kotlinOptions { | ||
jvmTarget = "1.8" | ||
freeCompilerArgs = | ||
listOf( | ||
// Adds OnlyInputTypes support | ||
"-Xallow-kotlin-package", | ||
) | ||
} | ||
} | ||
|
||
// =========================== | ||
// Code Quality checks | ||
// =========================== | ||
val customLicenseHeader = "/^(?s)(?!.*@custom-license-header).*/" | ||
|
||
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")) | ||
.named("standard") | ||
.onlyIfContentMatches("^(?!Copyright .*? Litote).*\$") | ||
} | ||
|
||
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")) | ||
} | ||
|
||
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.create("kotlinCheck") { | ||
description = "Runs all the kotlin checks" | ||
group = "verification" | ||
|
||
dependsOn("clean", "check") | ||
tasks.findByName("check")?.mustRunAfter("clean") | ||
} | ||
|
||
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.driver.kotlin.core" } } } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.