Skip to content

build(build-logic): fix Spotless targets for Kotlin scripts#2094

Open
dkamanin wants to merge 1 commit intoandroid:mainfrom
dkamanin:fix/spotless-targets
Open

build(build-logic): fix Spotless targets for Kotlin scripts#2094
dkamanin wants to merge 1 commit intoandroid:mainfrom
dkamanin:fix/spotless-targets

Conversation

@dkamanin
Copy link
Copy Markdown

@dkamanin dkamanin commented Apr 8, 2026

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.

@dkamanin dkamanin requested a review from dturner as a code owner April 8, 2026 17:50
Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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")
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

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.

Suggested change
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant