Hey guys, a quick question. I would like to config...
# ktlint
d
Hey guys, a quick question. I would like to configure the KtLintExtension for KtLint so it filters out certain folders. But I would like to configure this in one of my own ConventionPLugins in a BuildConfig module. But It seems like I don't have access to the KtLintExtension class. I can do the following in my build.gradle.kts files but not in my plugin. Am I doing something stupid? Or overseeing something?
Copy code
configure<org.jlleitschuh.gradle.ktlint.KtlintExtension> {
  filter {
    exclude { it.file.path.contains("generated") }
  }
}
v
What is the error you are get exactly? Optimally share it as build
--scan
URL
d
It's at compile time that i get the following Unresolved reference: jlleitschuh
Screenshot 2024-11-07 at 14.07.12.png
I find it weird that the class doesn't seem to be accessible my convention plugin.
v
You probably miss to declare the plugin as dependency for your plugin in the build script of your plugin
d
Can I do this with compileOnly ? I tried that already but no luck. Probably doing something wrong
v
Yes,
compileOnly
should also be fine, if the consumer will provide the plugin at runtime. If your plugin also applies the plugin, it is usually better to use
implementation
. But both should make the class available for compilation. Do you get that also when you build from commandline (to rule out that it just isn't synced to IDE properly)
d
Yess I ran a ./gradlew --scan command and it gave the same error. But I'll try again what I tried earlier
So to give some more information. I have a build.gradle.kts in my build-logic module. At the top i do the following
Copy code
plugins {
  `kotlin-dsl`
   alias(libs.plugins.org.jlleitschuh.gradle.ktlint)
}
And lower in the file i do the following
Copy code
dependencies {
  compileOnly(libs.android.gradlePlugin)
  compileOnly(libs.android.tools.common)
  compileOnly(libs.kotlin.gradlePlugin)
  compileOnly(libs.ksp.gradlePlugin)
  compileOnly(libs.plugins.org.jlleitschuh.gradle.ktlint)
}
v
compileOnly(<http://libs.plugins.org|libs.plugins.org>.jlleitschuh.gradle.ktlint)
this should not even compile. Can you share a full MCVE?
d
I made a MRE I added //KTLINT-TEST comments above the lines where my logic is and where i want to change things so you can search quickly
Sorry forgot something. This one is testable
It's indeed not compiling. But I just want to know how i can use the plugin as a dependency 🙂
v
Actually it should compile but fail at build script runtime. But anyway, for that question, there is https://github.com/gradle/gradle/issues/17963 including work-arounds
d
thanks @Vampire! Couldn't find anything but this saved my day
👌 1