This message was deleted.
# community-support
s
This message was deleted.
v
You or some plugin you apply probably already do
trimTrailingWhitespace()
somewhere. If I use what you pasted it works fine, if I double that line, I get the same error. Besides that this is not really so much a Gradle question, but more a question to the maintainers of that plugin.
j
I can’t find any other places where we define anything related to spotless and since it worked fine with legacy config, I thought I was doing something wrong with my gradle setup. I’ll search more into it 🤔
v
Maybe set a breakpoint in that method to break when it is called.
Legacy vs. new application should not really make a difference here I'd say
j
I see now that the
spotlessBlock
lies inside
allprojects
, probably to configure it for every module. That’s probably why it fails
Should I duplicate the configuration in each module’s
biold.gradle
or is there a clever way of doing this?
I see some tutorials online using
subprojects
instead, I’ll try with that
v
Using
allprojects { ... }
,
subprojects { ... }
,
project(...) { ... }
or similar means of doing cross-project configuration is actually bad practice and highly discouraged, as it immediately introduces project coupling and works against more sophisticated Gradle features and optimizations, besides making builds harder to read and harder to maintain. Instead you should consider using convention plugins, for example in
buildSrc
or an included build like
gradle/build-logic
for example implemented as precomplied script plugins.
And the only difference between all and sub is, that the project where you call it itself is not included.
j
Hi! I’m trying to use a convention now but I’m a bit unsure how to do it properly :
Copy code
class SpotlessConventionPlugin : Plugin<Project> {
    override fun apply(target: Project) {
        with(target) {
            apply(libs.findPlugin("spotless").get())

            configure<com.diffplug.gradle.spotless.SpotlessExtension> { <-- this type is not resolved since the plugin is applied dynamically I guess
                configureSpotless(this)
            }
        }
    }
}
How can I use the type
com.diffplug.gradle.spotless.SpotlessExtension
from there?
v
How or when the plugin is applied is irrelevant. You need to add a dependency on that plugin in the build script of the project building that plugin.
j
Thanks! I didn’t understand how it works but the type is resolved now
👌 1