Tidy the build files (#1814)

* Remove explicit dependency on compiler-embeddable

* Remove unnneeded task dependency

* Tidy up setting the Bintray user/pass

* Use type-safe accessors where possible

* Use tidy syntax

* Remove unused lines

* Remove unused repositories

* Avoid task configuration
This commit is contained in:
Matthew Haughton
2019-08-14 03:54:07 +10:00
committed by Artur Bosch
parent e087d221de
commit aabbcd8899
10 changed files with 82 additions and 122 deletions

View File

@@ -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<Detekt> {
tasks.withType<Detekt>().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<Detekt> {
tasks.withType<Detekt>().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<Test> {
tasks.withType<Test>().configureEach {
useJUnitPlatform()
testLogging {
// set options for log level LIFECYCLE
@@ -156,7 +155,7 @@ subprojects {
}
}
tasks.withType<KotlinCompile> {
tasks.withType<KotlinCompile>().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<PublishingExtension> {
publishing {
publications.create<MavenPublication>(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<ArtifactoryPluginConvention> {
setContextUrl("https://oss.jfrog.org/artifactory")
publish(delegateClosureOf<PublisherConfig> {
repository(delegateClosureOf<GroovyObject> {
@@ -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
}
}

View File

@@ -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<DokkaTask> {
tasks.withType<DokkaTask>().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<DokkaTask> {
jdkVersion = 8
}
tasks.withType<Test> {
tasks.withType<Test>().configureEach {
systemProperty("kotlinVersion", embeddedKotlinVersion)
doFirst {

View File

@@ -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<Jar> {
tasks.withType<Jar>().configureEach {
manifest {
attributes(mapOf("DetektVersion" to detektVersion))
}

View File

@@ -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"))

View File

@@ -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<Jar> {
tasks.withType<Jar>().configureEach {
from(
configurations["implementation"]
configurations.implementation.get()
.filter { "com.pinterest.ktlint" in it.toString() }
.map { if (it.isDirectory) it else zipTree(it) }
)

View File

@@ -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"))

View File

@@ -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")
}
}
}

View File

@@ -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"))

View File

@@ -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

View File

@@ -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"))