build(build-logic): fix Spotless targets for Kotlin scripts#2094
build(build-logic): fix Spotless targets for Kotlin scripts#2094dkamanin wants to merge 1 commit intoandroid:mainfrom
Conversation
There was a problem hiding this comment.
Code Review
This pull request refactors the Spotless configuration for Kotlin script files by consolidating multiple target patterns into a single function call. A review comment suggests using a recursive glob pattern for the build-logic directory to improve maintainability and ensure coverage of all script files in subdirectories.
| target("*.kts") | ||
| target("build-logic/*.kts") | ||
| target("build-logic/convention/*.kts") | ||
| target("*.kts", "build-logic/*.kts", "build-logic/convention/*.kts") |
There was a problem hiding this comment.
The current list of target patterns is quite specific and may miss .kts files in newly added modules or deeper directories within build-logic. Using a recursive glob pattern like build-logic/**/*.kts would be more robust and maintainable, ensuring all script files within the build logic are covered regardless of future changes to the directory structure.
| target("*.kts", "build-logic/*.kts", "build-logic/convention/*.kts") | |
| target("*.kts", "build-logic/**/*.kts") |
The current Spotless configuration for Kotlin scripts uses multiple target() calls. According to the Spotless Javadoc: "When this method is called multiple times, only the last call has any effect." Consequently, only files in 'build-logic/convention/*.kts' were being formatted, while root and 'build-logic' scripts were ignored. This commit consolidates all patterns into a single target() call to ensure all intended Kotlin scripts are properly tracked.
What I have done and why
While reviewing the build logic, I noticed that Kotlin script formatting is only applied to the last specified path. The
FormatExtension.target()method overwrites the internal state on each call rather than appending to it.Documentation reference:
This PR merges the target patterns into a single call:
target("*.kts", "build-logic/*.kts", "build-logic/convention/*.kts")This ensures that the license header and formatting rules are strictly enforced across all script files in the repository.
Note: This change does not introduce any immediate formatting changes to the existing files (they are already compliant), but it ensures they remain so in the future.