diff --git a/build.gradle.kts b/build.gradle.kts index f0f1542e2..9882da181 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -19,6 +19,7 @@ plugins { id("io.gitlab.arturbosch.detekt") id("org.jetbrains.dokka") version "0.9.18" apply false jacoco + `maven-publish` } buildScan { @@ -45,7 +46,7 @@ tasks.check { dependsOn(gradle.includedBuild("detekt-gradle-plugin").task(":check")) } -tasks.withType { +tasks.withType().configureEach { dependsOn(gradle.includedBuild("detekt-gradle-plugin").task(":detekt")) } @@ -59,8 +60,8 @@ tasks { subprojects .filterNot { it.name in listOf("detekt-test", "detekt-sample-extensions") } .forEach { - this@jacocoTestReport.sourceSets(it.sourceSets["main"]) - this@jacocoTestReport.dependsOn(it.tasks["test"]) + this@jacocoTestReport.sourceSets(it.sourceSets.main.get()) + this@jacocoTestReport.dependsOn(it.tasks.test) } reports { @@ -77,9 +78,7 @@ allprojects { version = detektVersion + if (System.getProperty("snapshot")?.toBoolean() == true) "-SNAPSHOT" else "" repositories { - mavenLocal() jcenter() - maven(url = "https://dl.bintray.com/arturbosch/generic") } } @@ -103,7 +102,7 @@ subprojects { jacoco.toolVersion = jacocoVersion } - tasks.withType { + tasks.withType().configureEach { exclude("resources/") exclude("build/") } @@ -130,7 +129,7 @@ subprojects { } } - val shadowedProjects = listOf("detekt-cli", "detekt-watcher", "detekt-generator") + val shadowedProjects = listOf("detekt-cli", "detekt-generator") if (project.name in shadowedProjects) { apply { @@ -139,7 +138,7 @@ subprojects { } } - tasks.withType { + tasks.withType().configureEach { useJUnitPlatform() testLogging { // set options for log level LIFECYCLE @@ -156,7 +155,7 @@ subprojects { } } - tasks.withType { + tasks.withType().configureEach { kotlinOptions.jvmTarget = "1.8" // https://youtrack.jetbrains.com/issue/KT-24946 kotlinOptions.freeCompilerArgs = listOf( @@ -168,18 +167,8 @@ subprojects { kotlinOptions.allWarningsAsErrors = shouldTreatCompilerWarningsAsErrors() } - val bintrayUser = - if (project.hasProperty("bintrayUser")) { - project.property("bintrayUser").toString() - } else { - System.getenv("BINTRAY_USER") - } - val bintrayKey = - if (project.hasProperty("bintrayKey")) { - project.property("bintrayKey").toString() - } else { - System.getenv("BINTRAY_API_KEY") - } + val bintrayUser = findProperty("bintrayUser")?.toString() ?: System.getenv("BINTRAY_USER") + val bintrayKey = findProperty("bintrayKey")?.toString() ?: System.getenv("BINTRAY_API_KEY") val detektPublication = "DetektPublication" bintray { @@ -216,9 +205,9 @@ subprojects { } val sourcesJar by tasks.creating(Jar::class) { - dependsOn("classes") + dependsOn(tasks.classes) archiveClassifier.set("sources") - from(sourceSets["main"].allSource) + from(sourceSets.main.get().allSource) } val javadocJar by tasks.creating(Jar::class) { @@ -231,7 +220,7 @@ subprojects { archives(javadocJar) } - configure { + publishing { publications.create(detektPublication) { from(components["java"]) artifact(sourcesJar) @@ -242,32 +231,32 @@ subprojects { groupId = this@subprojects.group as? String artifactId = this@subprojects.name version = this@subprojects.version as? String - pom.withXml { - asNode().apply { - appendNode("description", "Static code analysis for Kotlin") - appendNode("name", "detekt") - appendNode("url", "https://arturbosch.github.io/detekt") - - val license = appendNode("licenses").appendNode("license") - license.appendNode("name", "The Apache Software License, Version 2.0") - license.appendNode("url", "http://www.apache.org/licenses/LICENSE-2.0.txt") - license.appendNode("distribution", "repo") - - val developer = appendNode("developers").appendNode("developer") - developer.appendNode("id", "Artur Bosch") - developer.appendNode("name", "Artur Bosch") - developer.appendNode("email", "arturbosch@gmx.de") - - appendNode("scm").appendNode("url", "https://github.com/arturbosch/detekt") + pom { + description.set("Static code analysis for Kotlin") + name.set("detekt") + url.set("https://arturbosch.github.io/detekt") + licenses { + license { + name.set("The Apache Software License, Version 2.0") + url.set("http://www.apache.org/licenses/LICENSE-2.0.txt") + distribution.set("repo") + } + } + developers { + developer { + id.set("Artur Bosch") + name.set("Artur Bosch") + email.set("arturbosch@gmx.de") + } + } + scm { + url.set("https://github.com/arturbosch/detekt") } } } } - fun artifactory(configure: ArtifactoryPluginConvention.() -> Unit): Unit = - configure(project.convention.getPluginByName("artifactory")) - - artifactory { + configure { setContextUrl("https://oss.jfrog.org/artifactory") publish(delegateClosureOf { repository(delegateClosureOf { @@ -298,7 +287,7 @@ subprojects { kotlinTest("org.spekframework.spek2:spek-dsl-jvm:$spekVersion") } - sourceSets["main"].java.srcDirs("src/main/kotlin") + sourceSets.main.get().java.srcDirs("src/main/kotlin") } /** @@ -326,9 +315,9 @@ val detektFormat by tasks.registering(Detekt::class) { exclude("**/build/**") config = files("$rootDir/config/detekt/format.yml") reports { - xml { enabled = false } - html { enabled = false } - txt { enabled = false } + xml.enabled = false + html.enabled = false + txt.enabled = false } } diff --git a/detekt-api/build.gradle.kts b/detekt-api/build.gradle.kts index 10eb3ce87..fb263ef20 100644 --- a/detekt-api/build.gradle.kts +++ b/detekt-api/build.gradle.kts @@ -4,7 +4,7 @@ plugins { id("org.jetbrains.dokka") } -configurations.testImplementation.extendsFrom(configurations["kotlinTest"]) +configurations.testImplementation.get().extendsFrom(configurations.kotlinTest.get()) val yamlVersion: String by project val junitPlatformVersion: String by project @@ -21,7 +21,7 @@ dependencies { testRuntimeOnly("org.spekframework.spek2:spek-runner-junit5:$spekVersion") } -tasks.withType { +tasks.withType().configureEach { // suppresses undocumented classes but not dokka warnings https://github.com/Kotlin/dokka/issues/90 reportUndocumented = false outputFormat = "jekyll" @@ -30,7 +30,7 @@ tasks.withType { jdkVersion = 8 } -tasks.withType { +tasks.withType().configureEach { systemProperty("kotlinVersion", embeddedKotlinVersion) doFirst { diff --git a/detekt-cli/build.gradle.kts b/detekt-cli/build.gradle.kts index a031372ad..609964d13 100644 --- a/detekt-cli/build.gradle.kts +++ b/detekt-cli/build.gradle.kts @@ -9,13 +9,12 @@ val detektVersion: String by project val reflectionsVersion: String by project // implementation.extendsFrom kotlin is not enough for using cli in a gradle task - #58 -configurations.testImplementation.get().extendsFrom(configurations["kotlinTest"]) +configurations.testImplementation.get().extendsFrom(configurations.kotlinTest.get()) dependencies { implementation(project(":detekt-core")) runtimeOnly(project(":detekt-rules")) implementation("com.beust:jcommander:$jcommanderVersion") - implementation(kotlin("compiler-embeddable")) testImplementation(project(":detekt-test")) testImplementation(project(":detekt-rules")) @@ -24,10 +23,8 @@ dependencies { testRuntimeOnly("org.spekframework.spek2:spek-runner-junit5:$spekVersion") } -tasks["test"].dependsOn(":detekt-generator:generateDocumentation") - // bundle detekt's version for debug logging on rule exceptions -tasks.withType { +tasks.withType().configureEach { manifest { attributes(mapOf("DetektVersion" to detektVersion)) } diff --git a/detekt-core/build.gradle.kts b/detekt-core/build.gradle.kts index bb9fd5c84..34e99cb5b 100644 --- a/detekt-core/build.gradle.kts +++ b/detekt-core/build.gradle.kts @@ -1,11 +1,10 @@ -configurations.testImplementation.extendsFrom(configurations["kotlinTest"]) +configurations.testImplementation.get().extendsFrom(configurations.kotlinTest.get()) val junitPlatformVersion: String by project val spekVersion: String by project val reflectionsVersion: String by project dependencies { - implementation(kotlin("compiler-embeddable")) api(project(":detekt-api")) testImplementation(project(":detekt-rules")) diff --git a/detekt-formatting/build.gradle.kts b/detekt-formatting/build.gradle.kts index 5b68c4eba..bc4ae2a7a 100644 --- a/detekt-formatting/build.gradle.kts +++ b/detekt-formatting/build.gradle.kts @@ -1,13 +1,11 @@ -configurations["implementation"].isCanBeResolved = true -configurations.testImplementation.get() - .extendsFrom(configurations["kotlinTest"]) +configurations.implementation.get().isCanBeResolved = true +configurations.testImplementation.get().extendsFrom(configurations.kotlinTest.get()) val ktlintVersion: String by project val junitPlatformVersion: String by project val spekVersion: String by project dependencies { - implementation(kotlin("compiler-embeddable")) implementation(project(":detekt-api")) implementation("com.pinterest.ktlint:ktlint-ruleset-standard:$ktlintVersion") { exclude(group = "org.jetbrains.kotlin") @@ -25,9 +23,9 @@ dependencies { testRuntimeOnly("org.spekframework.spek2:spek-runner-junit5:$spekVersion") } -tasks.withType { +tasks.withType().configureEach { from( - configurations["implementation"] + configurations.implementation.get() .filter { "com.pinterest.ktlint" in it.toString() } .map { if (it.isDirectory) it else zipTree(it) } ) diff --git a/detekt-generator/build.gradle.kts b/detekt-generator/build.gradle.kts index 193c51aec..4abd58d7f 100644 --- a/detekt-generator/build.gradle.kts +++ b/detekt-generator/build.gradle.kts @@ -11,12 +11,12 @@ val jar by tasks.getting(Jar::class) { } // implementation.extendsFrom kotlin is not enough for using cli in a gradle task - #58 -configurations.testImplementation.get().extendsFrom(configurations["kotlinTest"]) +configurations.testImplementation.get().extendsFrom(configurations.kotlinTest.get()) val detektVersion: String by project -val generateDocumentation: Task by tasks.creating { - dependsOn(":detekt-generator:shadowJar") +val generateDocumentation by tasks.registering { + dependsOn(tasks.shadowJar) description = "Generates detekt documentation and the default config.yml based on Rule KDoc" group = "documentation" @@ -43,8 +43,8 @@ val generateDocumentation: Task by tasks.creating { } } -val verifyGeneratorOutput: Task by tasks.creating { - dependsOn(listOf(":detekt-generator:shadowJar", ":detekt-generator:generateDocumentation")) +val verifyGeneratorOutput by tasks.registering { + dependsOn(listOf(tasks.shadowJar, generateDocumentation)) description = "Verifies that all documentation and the config.yml are up-to-date" doLast { assertDefaultConfigUpToDate() @@ -91,7 +91,6 @@ dependencies { implementation(project(":detekt-rules")) implementation(project(":detekt-formatting")) implementation("com.beust:jcommander:$jcommanderVersion") - implementation(kotlin("compiler-embeddable")) implementation(kotlin("reflect")) testImplementation(project(":detekt-test")) diff --git a/detekt-gradle-plugin/build.gradle.kts b/detekt-gradle-plugin/build.gradle.kts index 2f1c6ce21..ef28f2aa0 100644 --- a/detekt-gradle-plugin/build.gradle.kts +++ b/detekt-gradle-plugin/build.gradle.kts @@ -3,17 +3,7 @@ import org.gradle.api.tasks.testing.logging.TestExceptionFormat import org.gradle.api.tasks.testing.logging.TestLogEvent import java.util.Date -buildscript { - repositories { - mavenCentral() - mavenLocal() - jcenter() - } -} - repositories { - gradlePluginPortal() - mavenLocal() jcenter() } @@ -31,8 +21,6 @@ plugins { group = "io.gitlab.arturbosch.detekt" version = "1.0.0" -val detektGradleVersion: String by project -val jcommanderVersion: String by project val spekVersion = "2.0.2" val junitPlatformVersion = "1.4.1" val assertjVersion = "3.12.2" @@ -102,7 +90,7 @@ tasks.dokka { outputDirectory = "$buildDir/javadoc" } -val generateDefaultDetektVersionFile: Task by tasks.creating { +val generateDefaultDetektVersionFile by tasks.registering { val defaultDetektVersionFile = File("$buildDir/generated/src/io/gitlab/arturbosch/detekt", "PluginVersion.kt") @@ -119,20 +107,20 @@ val generateDefaultDetektVersionFile: Task by tasks.creating { } } -sourceSets["main"].java.srcDir("$buildDir/generated/src") +sourceSets.main.get().java.srcDir("$buildDir/generated/src") tasks.compileKotlin { dependsOn(generateDefaultDetektVersionFile) } val sourcesJar by tasks.creating(Jar::class) { - dependsOn("classes") + dependsOn(tasks.classes) archiveClassifier.set("sources") - from(sourceSets["main"].allSource) + from(sourceSets.main.get().allSource) } val javadocJar by tasks.creating(Jar::class) { - dependsOn("dokka") + dependsOn(tasks.dokka) archiveClassifier.set("javadoc") from(buildDir.resolve("javadoc")) } @@ -148,18 +136,8 @@ detekt { project.rootDir.resolve("../config/detekt/detekt.yml") ) } -val bintrayUser: String? = - if (project.hasProperty("bintrayUser")) { - project.property("bintrayUser").toString() - } else { - System.getenv("BINTRAY_USER") - } -val bintrayKey: String? = - if (project.hasProperty("bintrayKey")) { - project.property("bintrayKey").toString() - } else { - System.getenv("BINTRAY_API_KEY") - } +val bintrayUser = findProperty("bintrayUser")?.toString() ?: System.getenv("BINTRAY_USER") +val bintrayKey = findProperty("bintrayKey")?.toString() ?: System.getenv("BINTRAY_API_KEY") val detektPublication = "DetektPublication" publishing { @@ -170,23 +148,26 @@ publishing { groupId = rootProject.group as? String artifactId = rootProject.name version = rootProject.version as? String - pom.withXml { - asNode().apply { - appendNode("description", "Static code analysis for Kotlin") - appendNode("name", "detekt") - appendNode("url", "https://github.com/arturbosch/detekt") - - val license = appendNode("licenses").appendNode("license") - license.appendNode("name", "The Apache Software License, Version 2.0") - license.appendNode("url", "http://www.apache.org/licenses/LICENSE-2.0.txt") - license.appendNode("distribution", "repo") - - val developer = appendNode("developers").appendNode("developer") - developer.appendNode("id", "Artur Bosch") - developer.appendNode("name", "Artur Bosch") - developer.appendNode("email", "arturbosch@gmx.de") - - appendNode("scm").appendNode("url", "https://github.com/arturbosch/detekt") + pom { + description.set("Static code analysis for Kotlin") + name.set("detekt") + url.set("https://github.com/arturbosch/detekt") + licenses { + license { + name.set("The Apache Software License, Version 2.0") + url.set("http://www.apache.org/licenses/LICENSE-2.0.txt") + distribution.set("repo") + } + } + developers { + developer { + id.set("Artur Bosch") + name.set("Artur Bosch") + email.set("arturbosch@gmx.de") + } + } + scm { + url.set("https://github.com/arturbosch/detekt") } } } diff --git a/detekt-rules/build.gradle.kts b/detekt-rules/build.gradle.kts index a07a4104f..78f5f1ac2 100644 --- a/detekt-rules/build.gradle.kts +++ b/detekt-rules/build.gradle.kts @@ -1,6 +1,6 @@ -configurations.testImplementation.extendsFrom(configurations["kotlinTest"]) +configurations.testImplementation.get().extendsFrom(configurations.kotlinTest.get()) -tasks["build"].finalizedBy(":detekt-generator:generateDocumentation") +tasks.build { finalizedBy(":detekt-generator:generateDocumentation") } val junitPlatformVersion: String by project val spekVersion: String by project @@ -8,7 +8,6 @@ val reflectionsVersion: String by project dependencies { implementation(project(":detekt-api")) - implementation(kotlin("compiler-embeddable")) testImplementation("org.reflections:reflections:$reflectionsVersion") testImplementation(project(":detekt-test")) diff --git a/detekt-sample-extensions/build.gradle.kts b/detekt-sample-extensions/build.gradle.kts index 709e444c9..dd1e24fb5 100644 --- a/detekt-sample-extensions/build.gradle.kts +++ b/detekt-sample-extensions/build.gradle.kts @@ -6,7 +6,6 @@ dependencies { // When creating a sample extension, change this dependency to the detekt-api version you build against, e.g. // io.gitlab.arturbosch.detekt:detekt-api:1.0.0-RC15 implementation(project(":detekt-api")) - implementation(kotlin("compiler-embeddable")) // When creating a sample extension, change this dependency to the detekt-test version you build against, e.g. // io.gitlab.arturbosch.detekt:detekt-test:1.0.0-RC15 diff --git a/detekt-test/build.gradle.kts b/detekt-test/build.gradle.kts index 17b266dde..014458f89 100644 --- a/detekt-test/build.gradle.kts +++ b/detekt-test/build.gradle.kts @@ -2,7 +2,6 @@ val assertjVersion: String by project dependencies { implementation(kotlin("script-runtime")) - implementation(kotlin("compiler-embeddable")) implementation(kotlin("script-util")) implementation(kotlin("scripting-compiler-embeddable"))