iamthevoid
05/27/2021, 10:02 AMgammax
05/27/2021, 11:07 AM..
or so.iamthevoid
05/27/2021, 11:12 AMallProjects
?gammax
05/27/2021, 11:13 AMiamthevoid
05/27/2021, 11:31 AMproject
|-lib
|-git-submodule-with-own-detect-configuration
|-detekt-config-files
|-sample-app
|-modulesFolder
|-module1
|-module2
|-etc
|-detekt-config-files
|-modulesFolder1
|-module1
|-module2
|-etc
|-modulesFolder2
|-module1
|-module2
|-etc
|-etc
detect-config-files is baseline.xml
and config.xml
. They stored in root project ang git-submodule-project with same relative path. Detekt configured in each of these projects in allProjects
section of root build.gradle.kts
like a:
fun Project.configureDetekt() {
apply(plugin = Dependencies.Detekt.plugin)
dependencies { detektPlugins(Dependencies.Detekt.detektFormatting) }
configureEachTask<Detekt> {
jvmTarget = Versions.jvmTarget
}
configure<DetektExtension> {
toolVersion = Versions.detekt
baseline = rootDirFile("config/detekt/baseline.xml")
input.setFrom(
"src/main/kotlin",
"src/main/java",
"src/commonMain/kotlin",
"src/androidMain/kotlin",
"src/iosMain/kotlin"
)
config = rootDirFiles("config/detekt/detekt.yml")
parallel = true
autoCorrect = true
reports {
xml {
enabled = true
destination = rootDirFile("build/report/detekt.xml")
}
txt {
enabled = true
destination = rootDirFile("build/report/detekt.txt")
}
}
}
}
When i run detekt on root project with
./gradlew detekt
it use root project build.gradle.kts
. And as configure<DetektExtension>
configures for plugin, but not for each task. I am getting the situation when submodule modules checking with root project rules.
I want to separate configs of root project and submodule project and somehow force to Detekt use concrete rules. It can be possible if config
and baseline
path can be modified from configureEachTask<Detekt>
block. But in task Detekt
both config
and baseline
properties declared as val
../..
in root build.gradle.kts
but must specify it for each separate moduleconfigureEachTask<Detekt> {
val isSubmoduleTask = {somehow by task name or path}
val configRoot = if (isSubmoduleTask) "submodule/path/" else "."
config = "$configRoot/config/detekt.yml"
baseline = "$configRoot/config/baseline.xml"
}
gammax
05/27/2021, 11:44 AMso i cant just use something likeWith Gradle you can always usein root../..
but must specify it for each separate modulebuild.gradle.kts
rootProject.files
and that will give you a path starting from the root project of your Gradle multi-project setup.iamthevoid
05/27/2021, 11:59 AMconfigure<DetektExtensions>
this configure
will be called for plugin, but not for each taskconfigure<DetektExtension>
will be appliedconfigure
in allProjects
block. Right?allProjects
gammax
05/27/2021, 12:16 PMiamthevoid
05/27/2021, 12:19 PM./gradlew detekt
called for base projectgammax
05/27/2021, 12:23 PMallProjects{}
and do an if-then-else
check inside for the project name. Not elegant, but is probably the best solution for you right now.iamthevoid
05/27/2021, 1:09 PMallprojects {
.................
configureDetekt()
}
And fun
fun Project.configureDetekt() {
apply(plugin = Dependencies.Detekt.plugin)
dependencies { detektPlugins(Dependencies.Detekt.detektFormatting) }
configureEachTask<Detekt> {
jvmTarget = Versions.jvmTarget
}
println("$name: ${rootProject.name}")
configure<DetektExtension> {
val isFromSubmodule = with(Dependencies.Modules.DesignSystem) {
listOf(shared, switches, typography, buttons).contains(path)
}
val configRoot = if (isFromSubmodule) "lib/design-system" else "."
toolVersion = Versions.detekt
baseline = rootDirFile("$configRoot/config/detekt/baseline.xml")
input.setFrom(
"src/main/kotlin",
"src/main/java",
"src/commonMain/kotlin",
"src/androidMain/kotlin",
"src/iosMain/kotlin"
)
config = rootDirFiles("$configRoot/config/detekt/detekt.yml")
parallel = true
autoCorrect = true
reports {
xml {
enabled = true
destination = rootDirFile("build/report/detekt.xml")
}
txt {
enabled = true
destination = rootDirFile("build/report/detekt.txt")
}
}
}
}
Here i assume that configure
applied for each project and it is (i checked with println
). But when i run ./gradlew detekt
i see detekt fails on submodule check, so i assume that detekt use base project config for submodule checkgammax
05/27/2021, 2:20 PMallProjects{}
and refactor your build logic a bit. Perhaps using a precompiled script plugin or just copy-n-pasting your build logic around.iamthevoid
05/27/2021, 2:22 PMgammax
05/27/2021, 2:22 PM