Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#575] [#586] Migrate to build version catalog #591

Merged
merged 6 commits into from
Jan 10, 2025

Conversation

ryan-conway
Copy link
Collaborator

@ryan-conway ryan-conway commented Nov 4, 2024

Solves #575
Solves #586

What happened 👀

  • Created libs.versions.toml
  • Deleted Dependencies.kt, Modules.kt, Plugins.kt and Versions.kt
  • Migrated app, data, domain and project gradle files to use new version catalog file

TODO in Part 2 🏃🏻

  • Update sample-compose to use libs.versions.toml

Insight 📝

  • We cannot delete Versions.kt as we cannot migrate all versions to the version catalog cleanly 🫠
  • COMPOSE_COMPILERversion will be removed in another PR 🙇🏻
  • We should handle version updates in a separate PR 👀

Proof Of Work 📹

App still builds and runs

Summary by CodeRabbit

Summary by CodeRabbit

  • Refactor

    • Migrated project to use centralized dependency management with TOML version catalog.
    • Replaced manual dependency and plugin declarations with library aliases.
    • Simplified build configuration across project modules.
  • Chores

    • Updated Gradle build scripts to use a more modern dependency management approach.
    • Removed legacy version and dependency constant files.
    • Introduced a structured approach for managing library versions and dependencies.
    • Changed root project name and enabled feature preview for type-safe project accessors.

@ryan-conway ryan-conway added this to the 3.31.0 milestone Nov 4, 2024
@ryan-conway ryan-conway self-assigned this Nov 4, 2024
@ryan-conway ryan-conway changed the title [#586] Migrate to version catalog [#586] Migrate to build version catalog Nov 4, 2024
Copy link

github-actions bot commented Nov 4, 2024

1 Warning
⚠️ Uh oh! Your project is under 80% coverage!

Kover report for template-compose:

🧛 Template - Compose Unit Tests Code Coverage: 61.54%

Coverage of Modified Files:

File Coverage

Modified Files Not Found In Coverage Report:

build.gradle.kts
build.gradle.kts
build.gradle.kts
build.gradle.kts
libs.versions.toml
settings.gradle.kts

Codebase cunningly covered by count Shroud 🧛

Generated by 🚫 Danger

Copy link

coderabbitai bot commented Jan 3, 2025

Walkthrough

The pull request introduces a comprehensive refactoring of dependency and plugin management in a Gradle-based Android project. The changes transition from using custom constant objects (Dependencies.kt, Plugins.kt, Versions.kt) to a more standardized approach using a centralized libs.versions.toml configuration file. This new approach leverages Gradle's version catalog feature, replacing hardcoded plugin and dependency references with alias-based declarations, which simplifies version management and improves build script readability across multiple modules.

Changes

File Change Summary
template-compose/app/build.gradle.kts Replaced plugin declarations with libs aliases and updated dependency management to use bundles and the libs.versions object.
template-compose/build.gradle.kts Updated plugin declarations to use libs aliases and modified Detekt tool version retrieval.
template-compose/buildSrc/src/main/java/Dependencies.kt Completely removed.
template-compose/buildSrc/src/main/java/Plugins.kt Completely removed.
template-compose/buildSrc/src/main/java/Versions.kt Removed multiple version constants.
template-compose/data/build.gradle.kts Migrated to libs aliases for plugins and dependencies, updated compileSdk and minSdk to use libs.versions object.
template-compose/domain/build.gradle.kts Updated plugin and dependency declarations using libs and consolidated test dependencies.
template-compose/gradle/libs.versions.toml New file added to centralize version, library, bundle, and plugin management.
template-compose/buildSrc/src/main/java/Modules.kt Completely removed.
template-compose/settings.gradle.kts Updated root project name and enabled feature preview for "TYPESAFE_PROJECT_ACCESSORS".

Sequence Diagram

sequenceDiagram
    participant Dev as Developer
    participant Gradle as Gradle Build System
    participant LibsCatalog as libs.versions.toml
    participant BuildScript as build.gradle.kts

    Dev->>LibsCatalog: Define library versions
    Dev->>LibsCatalog: Define library references
    Dev->>LibsCatalog: Create library bundles
    Dev->>BuildScript: Use libs aliases
    Gradle->>LibsCatalog: Resolve versions
    Gradle->>BuildScript: Compile project
Loading

Poem

🐰 Hop, hop, dependencies dance!
From constants to aliases, a gradle prance
Version catalog sings its sweet song
Modules now lean, dependencies strong
Refactoring magic, with bundles so bright! 🌟


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between ed21f0c and 8cca290.

📒 Files selected for processing (4)
  • template-compose/app/build.gradle.kts (3 hunks)
  • template-compose/buildSrc/src/main/java/Modules.kt (0 hunks)
  • template-compose/data/build.gradle.kts (2 hunks)
  • template-compose/settings.gradle.kts (1 hunks)
💤 Files with no reviewable changes (1)
  • template-compose/buildSrc/src/main/java/Modules.kt
🚧 Files skipped from review as they are similar to previous changes (1)
  • template-compose/app/build.gradle.kts
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: Verify newproject script
  • GitHub Check: Run Detekt and unit tests
🔇 Additional comments (8)
template-compose/settings.gradle.kts (2)

17-17: LGTM! Project name update follows naming conventions.

The removal of space in project name improves build system compatibility.


18-18: LGTM! Feature preview enables type-safe project accessors.

This enables type-safe project dependencies (e.g., projects.domain) which aligns with the version catalog migration.

template-compose/data/build.gradle.kts (6)

2-4: LGTM! Plugin declarations migrated to version catalog.

The plugin declarations now use the alias syntax which is the recommended approach for version catalogs.


9-9: LGTM! SDK versions now reference version catalog.

Using libs.versions for SDK configuration ensures consistent versioning across modules.

Also applies to: 12-12


47-47: LGTM! Project dependency uses type-safe accessor.

The projects.domain syntax provides type safety and better refactoring support.


49-53: LGTM! Core dependencies properly migrated to version catalog.

Dependencies are well-organized and use the new version catalog syntax.


55-58: LGTM! Network dependencies properly bundled.

Good use of bundles for retrofit and okhttp dependencies, with separate moshi configuration.


60-63: LGTM! Test dependencies aligned with previous discussions.

The test dependencies have been properly migrated to version catalog, and the inclusion of test.core.ktx aligns with the previous review discussion about Android-specific test dependencies.

Finishing Touches

  • 📝 Generate Docstrings

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@thawzintoe-ptut thawzintoe-ptut left a comment

Choose a reason for hiding this comment

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

LGTM

@thawzintoe-ptut
Copy link

Hi @ryan-conway, I was thinking about how we manage our SDK versions in the project and would like to propose a potential improvement. Here’s what I suggest we could declare in our TOML:

androidMinSdk = "24"
androidTargetSdk = "35"
androidVersionCode = "5"
androidVersionName = "0.37.0"

Then, we could easily refer to these in our Gradle scripts like this:

compileSdk = libs.versions.androidCompileSdk.get().toInt()

From my experience in previous projects, this approach has been quite effective.What do you think about this approach? Do you see any potential issues or improvements?

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (2)
template-compose/data/build.gradle.kts (1)

55-58: Consider adding comments to group dependencies

The network dependencies are well-organized using bundles. Consider adding comments to separate different dependency groups for better readability:

+    // Network
     api(libs.bundles.retrofit)
     api(libs.bundles.okhttp)
     api(libs.moshi)
     implementation(libs.bundles.moshi)
template-compose/app/build.gradle.kts (1)

154-160: Add back the suggested comments

Consider adding back the descriptive comments as suggested in the previous review:

+    // Unit test
     testImplementation(libs.bundles.unitTest)
     testImplementation(libs.test.turbine)

+    // UI test with Robolectric
     testImplementation(platform(libs.compose.bom))
     testImplementation(libs.bundles.uiTest)
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 3913d3f and ed21f0c.

📒 Files selected for processing (4)
  • template-compose/app/build.gradle.kts (3 hunks)
  • template-compose/data/build.gradle.kts (2 hunks)
  • template-compose/domain/build.gradle.kts (2 hunks)
  • template-compose/gradle/libs.versions.toml (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • template-compose/gradle/libs.versions.toml
  • template-compose/domain/build.gradle.kts
⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: Verify newproject script
  • GitHub Check: Review pull request
  • GitHub Check: Run Detekt and unit tests
🔇 Additional comments (10)
template-compose/data/build.gradle.kts (4)

2-4: LGTM! Plugin declarations correctly migrated to version catalog

The migration to version catalog syntax for plugins is well-implemented using the correct alias syntax.


9-9: LGTM! SDK versions correctly configured using version catalog

The SDK version configuration properly utilizes the version catalog with appropriate type conversion.

Also applies to: 12-12


49-51: LGTM! AndroidX dependencies properly structured

The implementation correctly separates datastore from the basic AndroidX bundle, following the previous review feedback.


60-62: LGTM! Test dependencies well-organized

Test dependencies are properly structured using bundles and individual declarations as needed.

template-compose/app/build.gradle.kts (6)

4-9: Consider migrating to KSP in a follow-up PR

The plugin declarations are correctly migrated to the version catalog. As discussed in previous comments, consider migrating from kapt to KSP in a follow-up PR for better build performance.


16-18: LGTM! Version code configuration properly implemented

The version code configuration correctly uses the version catalog while maintaining the ability to override via project properties.


23-23: LGTM! SDK and version configuration properly implemented

All SDK versions and version name are correctly sourced from the version catalog.

Also applies to: 27-30


137-138: LGTM! AndroidX dependencies properly organized

The implementation correctly separates datastore from the basic AndroidX bundle, following previous review feedback.


140-143: LGTM! Compose dependencies well-structured

The implementation correctly uses the Compose BOM and keeps accompanist separate from the basic Compose bundle.


100-102: Verify the timeline for compose compiler migration

The TODO comment correctly references issue #587 for the pending migration of the compose compiler version to the version catalog.

Run the following to check the issue status:

✅ Verification successful

Technical debt properly tracked for compose compiler migration

The hardcoded compose compiler version is acknowledged technical debt with a proper tracking issue (#587) that covers a comprehensive migration plan including Kotlin 2.1.0 upgrade, Compose Compiler Plugin adoption, and KSP migration.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
gh issue view 587

Length of output: 815

@ryan-conway ryan-conway force-pushed the feature/586-migrate-to-build-version-catalog branch from ed21f0c to 645f781 Compare January 8, 2025 10:56
Copy link
Member

@luongvo luongvo left a comment

Choose a reason for hiding this comment

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

All good

@luongvo
Copy link
Member

luongvo commented Jan 9, 2025

@ryan-conway I think you can start on part 2 for sample-compose now 💪

template-compose/data/build.gradle.kts Outdated Show resolved Hide resolved
id(Plugins.JAVA_LIBRARY)
id(Plugins.KOTLIN_JVM)
id(Plugins.KOVER)
id(libs.plugins.javaLibrary.get().pluginId)
Copy link
Contributor

Choose a reason for hiding this comment

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

Curious we can't apply alias as below?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

alias requires that plugin provides version, but java-library has no version 🫠

image

To force reading it from libs.versions.toml, the workaround is to still use id and read the plugin ID directly 🙈

Copy link
Contributor

Choose a reason for hiding this comment

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

@ryan-conway So we should add comment for clarification to avoid curiosity like me.hehe

Copy link
Contributor

@hoangnguyen92dn hoangnguyen92dn left a comment

Choose a reason for hiding this comment

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

LGTM 👍

@ryan-conway ryan-conway merged commit 692a83c into develop Jan 10, 2025
6 of 7 checks passed
@ryan-conway ryan-conway deleted the feature/586-migrate-to-build-version-catalog branch January 10, 2025 03:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Migrate to build version catalog
8 participants