android / architecture-samples

A collection of samples to discuss and showcase different architectural tools and patterns for Android apps.
Apache License 2.0
44.16k stars 11.6k forks source link

Update Spotless and ktlint - Code style rule changes #1002

Open dturner opened 3 months ago

dturner commented 3 months ago

What have I done and why tl;dr I have updated spotless and ktlint versions, however, this has resulted in some code style rule changes. This PR is to discuss:

Background Updating to gradle 8.6 causes the spotlessApply command to fail:

 ./gradlew --init-script gradle/init.gradle.kts spotlessApply
FAILURE: Build failed with an exception.

* What went wrong:
Configuration cache problems found in this build.

2 problems were found storing the configuration cache.
- Initialization script 'gradle/init.gradle.kts': external process started '/opt/homebrew/bin/git --version'
  See https://docs.gradle.org/8.6/userguide/configuration_cache.html#config_cache:requirements:external_processes
- Initialization script 'gradle/init.gradle.kts': external process started '/opt/homebrew/bin/git config --system --show-origin --list -z'
  See https://docs.gradle.org/8.6/userguide/configuration_cache.html#config_cache:requirements:external_processes

See the complete report at file:///Users/donturner/Code/workspace-android/architecture-samples/build/reports/configuration-cache/1esjztc97tjp4wgqxvsn7m1so/57o8ne9vw46zzt740jxphe4h9/configuration-cache-report.html
> Starting an external process '/opt/homebrew/bin/git --version' during configuration time is unsupported.
> Starting an external process '/opt/homebrew/bin/git config --system --show-origin --list -z' during configuration time is unsupported.

This has been fixed in Spotless 6.23 and above. Latest version is 6.25.0. However, updating results in another error:

e: file:///Users/donturner/Code/workspace-android/architecture-samples/gradle/init.gradle.kts:42:39: Unresolved reference: userData

FAILURE: Build failed with an exception.

* Where:
Initialization script '/Users/donturner/Code/workspace-android/architecture-samples/gradle/init.gradle.kts' line: 42

* What went wrong:
Script compilation error:

  Line 42:                 ktlint(ktlintVersion).userData(mapOf("android" to "true"))
                                                 ^ Unresolved reference: userData

1 error

This is because of a breaking change in which userData was removed when changing the default version of ktlint to 1.0.1.