spring-io / spring-javaformat

Apache License 2.0
812 stars 110 forks source link

Register `checkstyle` gradle task to check all source sets style #428

Closed quaff closed 1 week ago

quaff commented 1 week ago

It would be nice there is a built-in checkstyle task like format task apply to all source sets:

tasks.register("checkstyle") {
    sourceSets.map { "checkstyle" + it.name.replaceFirstChar(Char::titlecase) }.forEach(::dependsOn)
}
wilkinsona commented 1 week ago

Thanks for the suggestion. Unlike the various format tasks, which this plugin creates, the various checkstyle tasks are created by Gradle and the Java Format plugin doesn't interact with them at all. I'm not sure that should change by default as someone may be using the formatting but not using the checkstyle rules.

The suggestion above also assumes that each source set will have a checkstyle task which may not always be the case. An alternative would be to look for tasks by type. However, in a build like Spring Boot's, that would result in the checkstyleNohttp task being part of the general checkstyle task which we wouldn't want.

Thanks again for the suggestion, but I don't think we should do this as it may result in a build configuration that the user doesn't want. While it would be possible to make it configurable, that adds complexity that I'd rather avoid as well.