spotless icon indicating copy to clipboard operation
spotless copied to clipboard

`spotlessPredeclare` accessor is not available in kotlin scripts

Open bric3 opened this issue 5 months ago • 1 comments

In Gradle kotlin scripts, spotlessPredeclare is not available as an assessor. In order to use this , one has to access it via the extensions API, e.g. using kotlin's with.

with(extensions["spotlessPredeclare"] as SpotlessExtension) { ... }

Looking at the codebase, I noticed the spotlessPredeclare is not created when the plugin is applied.

https://github.com/diffplug/spotless/blob/db6a60eff69b7d37cfdceab0aff39100c05e422e/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/SpotlessPlugin.java#L51-L52

Maybe it's on purpose and I wonder why, but maybe it's not and maybe this can be added relatively easily.

bric3 avatar Jul 30 '25 08:07 bric3

spotlessPredeclare has two modes:

https://github.com/diffplug/spotless/blob/acc621eb709abddb093057c5cbb8f0e7345fb604/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/SpotlessExtension.java#L327-L343

Happy to take a PR which makes this more Kotlin-friendly.

nedtwigg avatar Aug 04 '25 20:08 nedtwigg