Steve Ramage
12/28/2020, 5:37 PMplugins {
...
id("io.gitlab.arturbosch.detekt") version "1.15.0" apply true
// ktlint linter - read more: <https://github.com/JLLeitschuh/ktlint-gradle>
id("org.jlleitschuh.gradle.ktlint") version "9.4.1" apply true
}
allprojects {
repositories {
mavenCentral()
jcenter()
}
apply(plugin = "io.gitlab.arturbosch.detekt")
apply(plugin = "org.jlleitschuh.gradle.ktlint")
dependencies {
detektPlugins("io.gitlab.arturbosch.detekt:detekt-formatting:1.14.2")
}
// Configure detekt plugin.
// Read more: <https://detekt.github.io/detekt/kotlindsl.html>
detekt {
config = files("${rootProject.projectDir}/detekt-config.yml")
buildUponDefaultConfig = true
reports {
html.enabled = false
xml.enabled = false
txt.enabled = false
}
}
tasks {
withType<Detekt> {
jvmTarget = "11"
}
}
}
I'm getting the following errors:
e: ./build.gradle.kts:74:9: Unresolved reference: detektPlugins
e: ./build.gradle.kts:80:5: Unresolved reference: detekt
e: ./build.gradle.kts:81:9: Unresolved reference: config
e: ./build.gradle.kts:82:9: Unresolved reference: buildUponDefaultConfig
e: ./build.gradle.kts:84:9: Unresolved reference: reports
e: ./build.gradle.kts:85:13: Unresolved reference: html
e: ./build.gradle.kts:85:18: Variable expected
e: ./build.gradle.kts:86:13: Unresolved reference: xml
e: ./build.gradle.kts:86:17: Variable expected
e: ./build.gradle.kts:87:13: Unresolved reference: txt
e: ./build.gradle.kts:87:17: Variable expected
mbonnin
12/28/2020, 5:38 PMplugins {}
blockSteve Ramage
12/28/2020, 5:40 PM^ Using 'plugins(PluginDependenciesSpec.() -> Unit): Nothing' is an error. The plugins {} block must not be used here. If you need to apply a plugin imperatively, please use apply<PluginType>() or apply(plugin = "id") instead.
mbonnin
12/28/2020, 5:42 PMconfigure<DetektExtension> {
...
}
Steve Ramage
12/28/2020, 5:43 PMmbonnin
12/28/2020, 5:43 PMdetekt {
}
Steve Ramage
12/28/2020, 5:44 PMmbonnin
12/28/2020, 5:46 PMSteve Ramage
12/28/2020, 5:47 PMmbonnin
12/28/2020, 5:47 PMVampire
12/29/2020, 9:18 AMapply true
which is the default anyway.
But accessor-wise it works perfectly fine.
I even copied your example, pasted it into an empty project, added the import for Detekt
and removed ...
and it worked without any problem.
The only thing I could imagine is, that you have other plugins applied too where the ...
is written and on of these fails to apply during generation of accessors, because in that case all accessors will not be available. And then with mbonnins suggestion it worked because you also fixed the other problem. But that is just a wild guess as long as you do not provide a reproducible example.
You're not getting the accessors generated because subprojects do not use theThat's pretty much non-sense, sorry. The scope of accessors is a build script, not any type of project. Theblockplugins {}
plugins
block of a script is applied to an empty project, then this project is investigated for all supported things (tasks, extensions, ...), for those accessors generated and then added to the class path of the script where the plugins
block resides for compilation of the remaining script. You can use it anywhere in that script, also in subprojects
or allprojects
closures, even with them being not the best practice anymore.mbonnin
12/29/2020, 9:34 AMYou can use it anywhere in that script, also inThat seems to contradict https://docs.gradle.org/current/userguide/plugins.html#sec:constrained_syntaxorsubprojects
closures, even with them being not the best practice anymore.allprojects
The plugins {} block must also be a top level statement in the buildscript. It cannot be nested inside another construct (e.g. an if-statement or for-loop)
Vampire
12/29/2020, 9:47 AMplugins
block, that will not work.
I said you can use the accessors.mbonnin
12/29/2020, 9:48 AMVampire
12/29/2020, 9:48 AMmbonnin
12/29/2020, 9:49 AMVampire
12/29/2020, 9:52 AMallprojects {
plugins {
id("io.gitlab.arturbosch.detekt") version "1.15.0"
}
dependencies {
detektPlugins("io.gitlab.arturbosch.detekt:detekt-formatting:1.14.2")
}
detekt {
buildUponDefaultConfig = true
}
}
This will work:
plugins {
id("io.gitlab.arturbosch.detekt") version "1.15.0"
}
allprojects {
apply(plugin = "io.gitlab.arturbosch.detekt")
dependencies {
detektPlugins("io.gitlab.arturbosch.detekt:detekt-formatting:1.14.2")
}
detekt {
buildUponDefaultConfig = true
}
}
This will also work:
plugins {
id("io.gitlab.arturbosch.detekt") version "1.15.0"
}
subprojects {
apply(plugin = "io.gitlab.arturbosch.detekt")
}
allprojects {
dependencies {
detektPlugins("io.gitlab.arturbosch.detekt:detekt-formatting:1.14.2")
}
detekt {
buildUponDefaultConfig = true
}
}
And now the super-question, why will this not work?
You can win a virtual cookie. :-)
plugins {
id("io.gitlab.arturbosch.detekt") version "1.15.0" apply false
}
allprojects {
apply(plugin = "io.gitlab.arturbosch.detekt")
dependencies {
detektPlugins("io.gitlab.arturbosch.detekt:detekt-formatting:1.14.2")
}
detekt {
buildUponDefaultConfig = true
}
}
mbonnin
12/29/2020, 9:52 AMVampire
12/29/2020, 9:53 AMallprojects {
apply(plugin = "io.gitlab.arturbosch.detekt")
does apply it, doesn't it?mbonnin
12/29/2020, 9:53 AMVampire
12/29/2020, 9:54 AMmbonnin
12/29/2020, 9:55 AMVampire
12/29/2020, 9:55 AM