Trying to use ktfmt with spotless. In my root I a...
# ktfmt
c
Trying to use ktfmt with spotless. In my root I added the plugin
Copy code
id("com.diffplug.spotless") version "5.12.4"
then I added this block in my root build.gradle.kts
Copy code
spotless {
    kotlin {
        ktfmt("0.24").dropboxStyle() // version and dropbox style are optional
    }
}
When I try to run
./gradlew spotlessCheck
I get
Copy code
Could not determine the dependencies of task ':spotlessCheck'.
> Could not create task ':spotlessKotlinCheck'.
   > Could not create task ':spotlessKotlin'.
      > You must either specify 'target' manually or apply a kotlin plugin.
Any ideas?
j
The plugin has to be applied to each project individually
And probably you have to add the target too if it keeps failing
Copy code
spotless {
    kotlin {
        target("src/**/*.kt")
        ktfmt().kotlinlangStyle()
    }
}
c
Darn. So I need to add the plugin block and spotless block for every module?
I have 10 modules. Not the worst thing, but just backwards to how I thought it worked. makes sense that you would set spotless on the project level no?
Tivi by chris banes seems to only have it in his root? https://github.com/chrisbanes/tivi/search?q=spotless
j
it is applying it inside subproject block
message has been deleted
c
@Javier ah. good catch. I posted a question on spotless' github and it seems like you don't need to apply it to every project. I'm using this
Copy code
configure<com.diffplug.gradle.spotless.SpotlessExtension> {
    kotlin {
        target("**/*.kt", "**/*.kts")
        targetExclude("$buildDir/**/*.kt")
        ktfmt("0.24").dropboxStyle()
    }
}
and everything seems to work correctly and it got applied to all of my modules!
j
c
@Javier thanks for the reference. I just set my target as above and it seems to work exactly how I expected so maybe something changed at some point? Maybe worth opening up an issue for clarification.
j
I am following the issue to check the answers. I checked the commits and I don't see a title which indicates that, so I am not sure if it is a non-intentional side effect from some commit.
c
@Javier thanks. Hopefully we get a response!
880 Views