mirror of
https://github.com/jlengrand/detekt.git
synced 2026-03-10 08:11:23 +00:00
Refactor so detekt-gradle-plugin can be added as an included build (#4094)
* Refactor publishing build config
This removes the use of `subprojects` block as it can't be used effectively
with composite builds.
* Make it easy to use detekt-gradle-plugin in a composite build
Replace `include("detekt-gradle-plugin")` with
`includeBuild("detekt-gradle-plugin")` in settings.gradle.kts
* Move nexus-staging-plugin config back to build-logic
This commit is contained in:
@@ -3,14 +3,12 @@ plugins {
|
||||
}
|
||||
|
||||
repositories {
|
||||
mavenLocal() // used to publish and test local gradle plugin changes
|
||||
mavenCentral()
|
||||
gradlePluginPortal()
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation(libs.kotlin.gradle)
|
||||
implementation(libs.detekt.gradle)
|
||||
implementation(libs.githubRelease.gradle)
|
||||
implementation(libs.semver4j.gradle)
|
||||
implementation(libs.nexusStaging.gradle)
|
||||
|
||||
@@ -1,36 +0,0 @@
|
||||
import io.gitlab.arturbosch.detekt.Detekt
|
||||
import io.gitlab.arturbosch.detekt.extensions.DetektExtension
|
||||
|
||||
plugins {
|
||||
id("io.gitlab.arturbosch.detekt")
|
||||
}
|
||||
|
||||
val baselineFile = file("$rootDir/config/detekt/baseline.xml")
|
||||
|
||||
tasks.withType<Detekt>().configureEach {
|
||||
jvmTarget = "1.8"
|
||||
}
|
||||
|
||||
detekt {
|
||||
source = objects.fileCollection().from(
|
||||
DetektExtension.DEFAULT_SRC_DIR_JAVA,
|
||||
"src/test/java",
|
||||
DetektExtension.DEFAULT_SRC_DIR_KOTLIN,
|
||||
"src/test/kotlin"
|
||||
)
|
||||
buildUponDefaultConfig = true
|
||||
baseline = baselineFile
|
||||
|
||||
reports {
|
||||
xml.enabled = true
|
||||
html.enabled = true
|
||||
txt.enabled = true
|
||||
sarif.enabled = true
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
detekt(project(":detekt-cli"))
|
||||
detektPlugins(project(":custom-checks"))
|
||||
detektPlugins(project(":detekt-formatting"))
|
||||
}
|
||||
@@ -4,10 +4,10 @@ import org.jetbrains.kotlin.gradle.plugin.KotlinSourceSet
|
||||
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
|
||||
|
||||
plugins {
|
||||
id("packaging")
|
||||
kotlin("jvm")
|
||||
`maven-publish`
|
||||
jacoco
|
||||
id("detekt")
|
||||
}
|
||||
|
||||
// bundle detekt's version for all jars to use it at runtime
|
||||
@@ -109,9 +109,3 @@ java {
|
||||
sourceCompatibility = JavaVersion.VERSION_1_8
|
||||
targetCompatibility = JavaVersion.VERSION_1_8
|
||||
}
|
||||
|
||||
publishing {
|
||||
publications.named<MavenPublication>(DETEKT_PUBLICATION) {
|
||||
from(components["java"])
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
plugins {
|
||||
`java-library` apply false
|
||||
`maven-publish` apply false
|
||||
signing apply false
|
||||
id("io.codearte.nexus-staging")
|
||||
`java-library`
|
||||
`maven-publish`
|
||||
signing
|
||||
}
|
||||
|
||||
val sonatypeUsername: String? = findProperty("sonatypeUsername")
|
||||
@@ -12,73 +11,59 @@ val sonatypePassword: String? = findProperty("sonatypePassword")
|
||||
?.toString()
|
||||
?: System.getenv("MAVEN_CENTRAL_PW")
|
||||
|
||||
nexusStaging {
|
||||
packageGroup = "io.gitlab.arturbosch"
|
||||
stagingProfileId = "1d8efc8232c5c"
|
||||
username = sonatypeUsername
|
||||
password = sonatypePassword
|
||||
publishing {
|
||||
repositories {
|
||||
maven {
|
||||
name = "mavenCentral"
|
||||
url = uri("https://oss.sonatype.org/service/local/staging/deploy/maven2")
|
||||
credentials {
|
||||
username = sonatypeUsername
|
||||
password = sonatypePassword
|
||||
}
|
||||
}
|
||||
maven {
|
||||
name = "sonatypeSnapshot"
|
||||
url = uri("https://oss.sonatype.org/content/repositories/snapshots")
|
||||
credentials {
|
||||
username = sonatypeUsername
|
||||
password = sonatypePassword
|
||||
}
|
||||
}
|
||||
}
|
||||
publications.register<MavenPublication>(DETEKT_PUBLICATION) {
|
||||
groupId = "io.gitlab.arturbosch.detekt"
|
||||
artifactId = project.name
|
||||
from(components["java"])
|
||||
version = Versions.currentOrSnapshot()
|
||||
pom {
|
||||
description.set("Static code analysis for Kotlin")
|
||||
name.set("detekt")
|
||||
url.set("https://detekt.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/detekt/detekt")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
subprojects {
|
||||
|
||||
apply {
|
||||
plugin("maven-publish")
|
||||
plugin("signing")
|
||||
}
|
||||
|
||||
publishing {
|
||||
repositories {
|
||||
maven {
|
||||
name = "mavenCentral"
|
||||
url = uri("https://oss.sonatype.org/service/local/staging/deploy/maven2")
|
||||
credentials {
|
||||
username = sonatypeUsername
|
||||
password = sonatypePassword
|
||||
}
|
||||
}
|
||||
maven {
|
||||
name = "sonatypeSnapshot"
|
||||
url = uri("https://oss.sonatype.org/content/repositories/snapshots")
|
||||
credentials {
|
||||
username = sonatypeUsername
|
||||
password = sonatypePassword
|
||||
}
|
||||
}
|
||||
}
|
||||
publications.register<MavenPublication>(DETEKT_PUBLICATION) {
|
||||
groupId = "io.gitlab.arturbosch.detekt"
|
||||
artifactId = project.name
|
||||
version = Versions.currentOrSnapshot()
|
||||
pom {
|
||||
description.set("Static code analysis for Kotlin")
|
||||
name.set("detekt")
|
||||
url.set("https://detekt.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/detekt/detekt")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (findProperty("signing.keyId") != null) {
|
||||
signing {
|
||||
sign(publishing.publications[DETEKT_PUBLICATION])
|
||||
}
|
||||
} else {
|
||||
logger.info("Signing Disabled as the PGP key was not found")
|
||||
if (findProperty("signing.keyId") != null) {
|
||||
signing {
|
||||
sign(publishing.publications[DETEKT_PUBLICATION])
|
||||
}
|
||||
} else {
|
||||
logger.info("Signing Disabled as the PGP key was not found")
|
||||
}
|
||||
|
||||
@@ -2,6 +2,18 @@ import com.vdurmont.semver4j.Semver
|
||||
|
||||
plugins {
|
||||
id("com.github.breadmoirai.github-release")
|
||||
id("io.codearte.nexus-staging")
|
||||
}
|
||||
|
||||
nexusStaging {
|
||||
packageGroup = "io.gitlab.arturbosch"
|
||||
stagingProfileId = "1d8efc8232c5c"
|
||||
username = findProperty("sonatypeUsername")
|
||||
?.toString()
|
||||
?: System.getenv("MAVEN_CENTRAL_USER")
|
||||
password = findProperty("sonatypePassword")
|
||||
?.toString()
|
||||
?: System.getenv("MAVEN_CENTRAL_PW")
|
||||
}
|
||||
|
||||
project.afterEvaluate {
|
||||
@@ -46,6 +58,7 @@ fun updateVersion(increment: (Semver) -> Semver) {
|
||||
}
|
||||
versionsFile.writeText("$newContent\n")
|
||||
}
|
||||
|
||||
tasks {
|
||||
register("incrementPatch") { doLast { updateVersion { it.nextPatch() } } }
|
||||
register("incrementMinor") { doLast { updateVersion { it.nextMinor() } } }
|
||||
|
||||
@@ -2,9 +2,8 @@ import io.gitlab.arturbosch.detekt.Detekt
|
||||
import io.gitlab.arturbosch.detekt.DetektCreateBaselineTask
|
||||
|
||||
plugins {
|
||||
id("packaging")
|
||||
id("releasing")
|
||||
id("detekt")
|
||||
alias(libs.plugins.detekt)
|
||||
alias(libs.plugins.gradleVersionz)
|
||||
alias(libs.plugins.sonarqube)
|
||||
}
|
||||
@@ -12,6 +11,36 @@ plugins {
|
||||
allprojects {
|
||||
group = "io.gitlab.arturbosch.detekt"
|
||||
version = Versions.currentOrSnapshot()
|
||||
|
||||
apply(plugin = "io.gitlab.arturbosch.detekt")
|
||||
|
||||
detekt {
|
||||
source = objects.fileCollection().from(
|
||||
io.gitlab.arturbosch.detekt.extensions.DetektExtension.DEFAULT_SRC_DIR_JAVA,
|
||||
"src/test/java",
|
||||
io.gitlab.arturbosch.detekt.extensions.DetektExtension.DEFAULT_SRC_DIR_KOTLIN,
|
||||
"src/test/kotlin"
|
||||
)
|
||||
buildUponDefaultConfig = true
|
||||
baseline = file("$rootDir/config/detekt/baseline.xml")
|
||||
|
||||
reports {
|
||||
xml.enabled = true
|
||||
html.enabled = true
|
||||
txt.enabled = true
|
||||
sarif.enabled = true
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
detekt(project(":detekt-cli"))
|
||||
detektPlugins(project(":custom-checks"))
|
||||
detektPlugins(project(":detekt-formatting"))
|
||||
}
|
||||
|
||||
tasks.withType<Detekt>().configureEach {
|
||||
jvmTarget = "1.8"
|
||||
}
|
||||
}
|
||||
|
||||
val analysisDir = file(projectDir)
|
||||
|
||||
@@ -18,7 +18,6 @@ dependencies {
|
||||
compileOnly(libs.kotlin.gradle)
|
||||
compileOnly(gradleKotlinDsl())
|
||||
|
||||
testImplementation(projects.detektTestUtils)
|
||||
testImplementation(libs.kotlin.gradle)
|
||||
testImplementation(libs.bundles.testImplementation)
|
||||
testRuntimeOnly(libs.spek.runner)
|
||||
|
||||
11
detekt-gradle-plugin/settings.gradle.kts
Normal file
11
detekt-gradle-plugin/settings.gradle.kts
Normal file
@@ -0,0 +1,11 @@
|
||||
pluginManagement {
|
||||
includeBuild("../build-logic")
|
||||
}
|
||||
|
||||
dependencyResolutionManagement {
|
||||
versionCatalogs {
|
||||
create("libs") {
|
||||
from(files("../gradle/libs.versions.toml"))
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,10 +1,10 @@
|
||||
package io.gitlab.arturbosch.detekt.report
|
||||
|
||||
import io.github.detekt.test.utils.resourceAsFile
|
||||
import org.assertj.core.api.Assertions.assertThat
|
||||
import org.spekframework.spek2.Spek
|
||||
import org.spekframework.spek2.style.specification.describe
|
||||
import java.io.File
|
||||
import java.net.URL
|
||||
|
||||
internal class SarifReportMergerSpec : Spek({
|
||||
describe("sarif report merger") {
|
||||
@@ -19,3 +19,14 @@ internal class SarifReportMergerSpec : Spek({
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
internal object Resources
|
||||
|
||||
internal fun resourceUrl(name: String): URL {
|
||||
val explicitName = if (name.startsWith("/")) name else "/$name"
|
||||
val resource = Resources::class.java.getResource(explicitName)
|
||||
requireNotNull(resource) { "Make sure the resource '$name' exists!" }
|
||||
return resource
|
||||
}
|
||||
|
||||
internal fun resourceAsFile(name: String): File = File(resourceUrl(name).path)
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package io.github.detekt.test.utils
|
||||
|
||||
import java.io.File
|
||||
import java.net.URI
|
||||
import java.net.URL
|
||||
import java.nio.file.Files
|
||||
@@ -20,8 +19,6 @@ fun resource(name: String): URI = resourceUrl(name).toURI()
|
||||
|
||||
fun resourceAsPath(name: String): Path = Paths.get(resource(name))
|
||||
|
||||
fun resourceAsFile(name: String): File = File(resourceUrl(name).path)
|
||||
|
||||
fun readResourceContent(name: String): String {
|
||||
val path = resourceAsPath(name)
|
||||
return Files.readAllLines(path).joinToString("\n") + "\n"
|
||||
|
||||
@@ -6,7 +6,6 @@ ktlint = "0.42.1"
|
||||
spek = "2.0.17"
|
||||
|
||||
[libraries]
|
||||
detekt-gradle = "io.gitlab.arturbosch.detekt:detekt-gradle-plugin:1.18.1"
|
||||
githubRelease-gradle = "com.github.breadmoirai:github-release:2.2.12"
|
||||
nexusStaging-gradle = "io.codearte.gradle.nexus:gradle-nexus-staging-plugin:0.22.0"
|
||||
semver4j-gradle = "com.vdurmont:semver4j:3.1.0"
|
||||
@@ -42,6 +41,7 @@ jcommander = "com.beust:jcommander:1.81"
|
||||
|
||||
[plugins]
|
||||
binaryCompatibilityValidator = { id = "org.jetbrains.kotlinx.binary-compatibility-validator", version = "0.7.0" }
|
||||
detekt = { id = "io.gitlab.arturbosch.detekt", version = "1.18.1" }
|
||||
dokka = { id = "org.jetbrains.dokka", version.ref = "dokka" }
|
||||
gradleVersionz = { id = "com.github.ben-manes.versions", version = "0.39.0" }
|
||||
pluginPublishing = { id = "com.gradle.plugin-publish", version = "0.15.0" }
|
||||
|
||||
@@ -4,37 +4,35 @@ pluginManagement {
|
||||
includeBuild("build-logic")
|
||||
}
|
||||
|
||||
include(
|
||||
"code-coverage-report",
|
||||
"custom-checks",
|
||||
"detekt-api",
|
||||
"detekt-cli",
|
||||
"detekt-core",
|
||||
"detekt-formatting",
|
||||
"detekt-generator",
|
||||
"detekt-gradle-plugin",
|
||||
"detekt-metrics",
|
||||
"detekt-parser",
|
||||
"detekt-psi-utils",
|
||||
"detekt-report-html",
|
||||
"detekt-report-sarif",
|
||||
"detekt-report-txt",
|
||||
"detekt-report-xml",
|
||||
"detekt-rules",
|
||||
"detekt-rules-complexity",
|
||||
"detekt-rules-coroutines",
|
||||
"detekt-rules-documentation",
|
||||
"detekt-rules-empty",
|
||||
"detekt-rules-errorprone",
|
||||
"detekt-rules-exceptions",
|
||||
"detekt-rules-naming",
|
||||
"detekt-rules-performance",
|
||||
"detekt-rules-style",
|
||||
"detekt-sample-extensions",
|
||||
"detekt-test",
|
||||
"detekt-test-utils",
|
||||
"detekt-tooling"
|
||||
)
|
||||
include("code-coverage-report")
|
||||
include("custom-checks")
|
||||
include("detekt-api")
|
||||
include("detekt-cli")
|
||||
include("detekt-core")
|
||||
include("detekt-formatting")
|
||||
include("detekt-generator")
|
||||
include("detekt-gradle-plugin")
|
||||
include("detekt-metrics")
|
||||
include("detekt-parser")
|
||||
include("detekt-psi-utils")
|
||||
include("detekt-report-html")
|
||||
include("detekt-report-sarif")
|
||||
include("detekt-report-txt")
|
||||
include("detekt-report-xml")
|
||||
include("detekt-rules")
|
||||
include("detekt-rules-complexity")
|
||||
include("detekt-rules-coroutines")
|
||||
include("detekt-rules-documentation")
|
||||
include("detekt-rules-empty")
|
||||
include("detekt-rules-errorprone")
|
||||
include("detekt-rules-exceptions")
|
||||
include("detekt-rules-naming")
|
||||
include("detekt-rules-performance")
|
||||
include("detekt-rules-style")
|
||||
include("detekt-sample-extensions")
|
||||
include("detekt-test")
|
||||
include("detekt-test-utils")
|
||||
include("detekt-tooling")
|
||||
|
||||
enableFeaturePreview("VERSION_CATALOGS")
|
||||
enableFeaturePreview("TYPESAFE_PROJECT_ACCESSORS")
|
||||
|
||||
Reference in New Issue
Block a user