https://kotlinlang.org logo
#ktlint
Title
# ktlint
s

Stylianos Gakis

11/09/2023, 1:14 AM
For the Kotlinter users out there, have you managed to use ktlint 1.0 + kotlinter 4.0 along with compose yet? I’ve tried forcing the ktlint version to 1.0.1 as shown in the docs, and use
ktlint_function_naming_ignore_when_annotated_with=Composable
in my editorconfig but it seems like it’s still failing to accept that for me. If anyone has gotten this to work I’d love to hear about what I’ve done wrong here.
m

mateusz.kwiecinski

11/09/2023, 8:56 AM
Have you tried killing the gradle daemon (
./gradlew --stop
) after modifying
.editorconfig
file? There is a known issue where this line prevents it discovering file changes after failed builds (which are not considered incremental) 🙂
s

Stylianos Gakis

11/09/2023, 9:01 AM
Hmm good idea, that didn’t work unfortunately though still. I feel like I may be putting the
resolutionStrategy.force
in the wrong place in my project and it’s not getting picked up properly. I tried in the settings.gradle.kts first, with the snippet exactly copied over from the docs
Copy code
buildscript {
  configurations.classpath {
    resolutionStrategy {
      force(
        "com.pinterest.ktlint:ktlint-rule-engine:1.0.1",
        "com.pinterest.ktlint:ktlint-rule-engine-core:1.0.1",
        "com.pinterest.ktlint:ktlint-cli-reporter-core:1.0.1",
        "com.pinterest.ktlint:ktlint-cli-reporter-checkstyle:1.0.1",
        "com.pinterest.ktlint:ktlint-cli-reporter-json:1.0.1",
        "com.pinterest.ktlint:ktlint-cli-reporter-html:1.0.1",
        "com.pinterest.ktlint:ktlint-cli-reporter-plain:1.0.1",
        "com.pinterest.ktlint:ktlint-cli-reporter-sarif:1.0.1",
        "com.pinterest.ktlint:ktlint-ruleset-standard:1.0.1",
      )
    }
  }
}
That didn’t help, and I tried adding it in the :app module’s build.gradle.kts, that didn’t work, also tried adding it to the convention plugin which applies kotlinter to each module, smth like:
Copy code
class KtlintConventionPlugin : Plugin<Project> {
  override fun apply(target: Project) {
    with(target) {
      val libs = the<LibrariesForLibs>()
      with(pluginManager) {
        apply(libs.plugins.kotlinter.get().pluginId)
      }

      configurations.all {
        resolutionStrategy {
          force(
            "com.pinterest.ktlint:ktlint-rule-engine:1.0.1",
            "com.pinterest.ktlint:ktlint-rule-engine-core:1.0.1",
            "com.pinterest.ktlint:ktlint-cli-reporter-core:1.0.1",
            "com.pinterest.ktlint:ktlint-cli-reporter-checkstyle:1.0.1",
            "com.pinterest.ktlint:ktlint-cli-reporter-json:1.0.1",
            "com.pinterest.ktlint:ktlint-cli-reporter-html:1.0.1",
            "com.pinterest.ktlint:ktlint-cli-reporter-plain:1.0.1",
            "com.pinterest.ktlint:ktlint-cli-reporter-sarif:1.0.1",
            "com.pinterest.ktlint:ktlint-ruleset-standard:1.0.1",
          )
        }
      }
      // more stuff here...
    }
  }
}
Didn’t work either. I am worried about this one in particular because it’s not something I’ve done before so I don’t know how to check if I am doing it right 😄
Have you managed to bump to Kotlinter 4.x and Ktlint 1.x while also managing to suppress this false positive? If you’ve done it correctly then maybe at least I know I’m doing something wrong, and not that it’s impossible 😄
m

mateusz.kwiecinski

11/09/2023, 9:10 AM
Yeah,
setting.gradle
is a different project, In convention plugin you're configuring configurations of the project
KtlintConventionPlugin
has been applied to, not the
buildscript
. Putting the
resolutionStrategy
to "regular" build.gradle file should do the trick, although I remembered modifying buildscript.classpath is tricky and has doesn't work in certain circumstances 👀
Have you managed to bump to Kotlinter 4.x and Ktlint 1.x while also managing to suppress this false positive?
I'm not using kotlinter anymore and I started maintaining my own fork https://github.com/usefulness/ktlint-gradle-plugin of it. You can give it a try if you want 🙂
👀 1
s

Stylianos Gakis

11/09/2023, 9:15 AM
Haha I knew I must’ve been doing something wrong then. There’s approximately 0% chance I would’ve found this by myself 😂 This seems to work, thanks a ton!
10 Views