spring-io / spring-javaformat

Apache License 2.0
795 stars 110 forks source link

Update README: solution for excluding a package from being checked doesn't work #405

Closed brendonmiranda closed 4 months ago

brendonmiranda commented 6 months ago

The documentation indicates a way for excluding packages from being checked that doesn't work (spotted on gradle 7.5):

In case you want to exclude a package from being checked, for example if you generate sources, you can do this by adding following configuration:

tasks.withType(io.spring.javaformat.gradle.tasks.CheckFormat) {
exclude "package/to/exclude"
}

When trying to find a solution to exclude generated source packages I was able to find one in the spring-boot's build.gradle: https://github.com/spring-projects/spring-boot/blob/107dc5338ba8aff35e2ecb8f6872e23f4ab9e979/spring-boot-project/spring-boot/build.gradle#L160C1-L166C2

The documentation solution can be updated to the following:

tasks.withType(io.spring.javaformat.gradle.tasks.CheckFormat) {
    def generatedSources = fileTree("package/to/exclude")
    exclude { candidate -> generatedSources.contains(candidate.file) }
}

I'd love to open a PR if this change is agreed. Thanks.

wilkinsona commented 6 months ago

It works for me as shown in the README. Can you please share a minimal example that shows it not working?