build: add Spotless with ktlint formatting checks by kikoso · Pull Request #2452 · googlemaps-samples/android-samples · GitHub
Skip to content

build: add Spotless with ktlint formatting checks - #2452

Merged
dkhawk merged 2 commits into
mainfrom
build/add-spotless
Oct 14, 2026
Merged

dkhawk merged 2 commits into
mainfrom
build/add-spotless

Conversation

@kikoso

@kikoso kikoso commented Oct 14, 2026

Copy link
Copy Markdown
Collaborator

Adds Spotless with ktlint (Kotlin) and google-java-format (Java) so formatting is checked automatically on pull requests, instead of in review comments.

The configuration matches the one already used in android-maps3d-samples, so all the Maps Android repos format code the same way.

Changes

  • build: add Spotless with ktlint...:
    • Spotless 8.9.0 in the version catalog and one root spotless {} block covering every .kt and .java file, including the tutorials outside the Gradle build.
    • Java uses googleJavaFormat().aosp() (4-space), matching the existing code. .editorconfig now has max_line_length = 120 for Kotlin.
    • A ./gradlew spotlessCheck step in the lint job of lint.yml, and a note in CONTRIBUTING.md to run ./gradlew spotlessApply before opening a PR.
  • style: apply Spotless formatting: the output of ./gradlew spotlessApply, plus manual, behaviour-neutral fixes ktlint cannot do on its own: wildcard imports replaced, misplaced KDocs turned into block comments, long lines wrapped, and long string literals (mostly @Sample / @SnippetItem descriptions) split with + so their values are unchanged. Seven lines over 120 characters are suppressed instead (raw-string Gemini prompts and one URL).

Disabled ktlint rules, so this stays formatting-only:

  • package-name, property-naming, backing-property-naming, filename: fixing them would mean renames.
  • annotation-spacing: in several ApiDemos files the // [START ...] tag sits between @Sample(...) and the class, and this rule would move the tag above the annotation, pulling @Sample into the published snippet.

Region tags

Checked against main: every file has the same [START / [END tags in the same order, each still on its own line, and no code moved into or out of a region. Code inside some regions is re-indented or reformatted (for example trailing commas or expression bodies), so the published snippets will look slightly different after the next docs sync.

Merging

Please use rebase and merge so the reformat stays a separate commit. After merging, I will add its SHA to .git-blame-ignore-revs in a small follow-up, so git blame skips it.

Open PRs will likely need a rebase and a ./gradlew spotlessApply after this lands.

Verification

./gradlew spotlessCheck assembleDebug testDebugUnitTest pass locally, and the androidTest sources for snippets:kotlin-app and ApiDemos:kotlin-app compile.

Adds the Spotless Gradle plugin (8.9.0) with ktlint for Kotlin and google-java-format (AOSP style) for Java, runs ./gradlew spotlessCheck in the lint workflow, and documents ./gradlew spotlessApply in CONTRIBUTING.md.
Output of ./gradlew spotlessApply, plus manual, behaviour-neutral fixes for violations ktlint cannot fix on its own (wildcard imports, misplaced KDoc, long lines and string literals split with +). Documentation region tags are unchanged in count, order and position. No identifiers were renamed.
@snippet-bot

snippet-bot Bot commented Oct 14, 2026

Copy link
Copy Markdown

Comment thread gradle/libs.versions.toml Dismissed
Comment thread snippets/kotlin-app/src/main/java/com/example/snippets/kotlin/MapActivity.kt Dismissed
Comment thread snippets/kotlin-app/src/main/java/com/example/snippets/kotlin/MapActivity.kt Dismissed
Comment thread snippets/kotlin-app/src/main/java/com/example/snippets/kotlin/TrackedMap.kt Dismissed
Comment thread snippets/kotlin-app/src/main/java/com/example/snippets/kotlin/TrackedMap.kt Dismissed
@dkhawk
dkhawk merged commit b23df3a into main Oct 14, 2026
20 checks passed
@dkhawk
dkhawk deleted the build/add-spotless branch October 14, 2026 15:23
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.

3 participants