Xavier F. Gouchet
09/27/2019, 4:00 PMdetekt.gradle
that would apply the same detekt config to all projects needing it.
Now when I try to do that, I can still use the apply(from("path/to/detekt.settings.gradle.kts"))
, but apparently anything I put in the settings script doesn't have the usual imports, and cannot resolve any of the extensions.Xavier F. Gouchet
09/27/2019, 4:00 PMdetekt.settings.gradle.kts
have this inside :
detekt {
version = "1.0.1"
input = files("$projectDir/src/main/kotlin")
config = files("$project.rootDir/script/config/detekt.yml")
reports {
xml {
enabled = true
destination = file("build/reports/detekt.xml")
}
}
}
Xavier F. Gouchet
09/27/2019, 4:03 PMtapchicoma
09/27/2019, 8:16 PMbuildSrc
module: https://docs.gradle.org/current/userguide/organizing_gradle_projects.html#sec:build_sources
And create extension function for Project
something like this: https://github.com/gradle/kotlin-dsl-samples/blob/master/samples/multi-kotlin-project-with-buildSrc/buildSrc/src/main/kotlin/utils.ktXavier F. Gouchet
09/28/2019, 3:34 PMbuildSrc
for thatXavier F. Gouchet
09/28/2019, 3:34 PMXavier F. Gouchet
09/28/2019, 3:39 PMbuildSrc
folder.Xavier F. Gouchet
09/28/2019, 3:40 PMtapchicoma
09/28/2019, 3:40 PMbuildSrc
Xavier F. Gouchet
09/28/2019, 4:14 PMXavier F. Gouchet
09/28/2019, 4:14 PMpg
09/30/2019, 7:49 AMdetekt
in buildSrc
? It's exactly what I tried to achieve yesterday without success πXavier F. Gouchet
09/30/2019, 8:15 AMbuildSrc/build.gradle.kts
:
dependencies {
compile ("io.gitlab.arturbosch.detekt:detekt-gradle-plugin:1.0.1")
}
Xavier F. Gouchet
09/30/2019, 8:17 AMbuildSrc/src/main/kotlin/com/example/DetektConfig.kt
package com.example
import io.gitlab.arturbosch.detekt.extensions.DetektExtension
import org.gradle.api.Project
fun Project.detektConfig() {
val ext: DetektExtension? = extensions.findByType(DetektExtension::class)
ext?.apply {
version = "1.0.1"
input = files("$projectDir/src/main/kotlin")
config = files("${project.rootDir}/script/config/detekt.yml")
reports {
xml {
enabled = true
destination = file("build/reports/detekt.xml")
}
}
}
}
Xavier F. Gouchet
09/30/2019, 8:17 AMdetektConfig()
from any build.gradle.kts
script in any moduletapchicoma
09/30/2019, 8:20 AMbuildSrc
that configures detekt (and some other common stuff) and apply it to all modulespg
09/30/2019, 9:22 AMtapchicoma
09/30/2019, 9:23 AMtapchicoma
09/30/2019, 9:23 AMProject
extension functions in the buildSrc
Xavier F. Gouchet
09/30/2019, 9:25 AMpg
09/30/2019, 9:31 AM<http://android.app|android.app>
with android-kotlin
and one for pure kotlin library, both with default configs and core deps. Effect is lovelyhenrik
09/30/2019, 11:24 AMdetektConfig()
?Xavier F. Gouchet
09/30/2019, 11:30 AMhenrik
09/30/2019, 11:37 AM