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

[#586] Migrate to build version catalog (2/2) #596

Merged

Conversation

ryan-conway
Copy link
Collaborator

@ryan-conway ryan-conway commented Jan 10, 2025

#586

What happened 👀

  • Added libs.versions.toml
  • Updated gradle version from 7.5 to 8.0
  • Updated module build.gradle files
    • Added namespace
    • Added buildConfig = true to buildFeatures
    • Updated Java version from 11 to 17
  • Updated project build.gradle
    • Removed buildScript and allProjects blocks
    • Updated Java version from 11 to 17
  • Updated settings.gradle
    • Added pluginManagement and dependencyResolutionManagement blocks
    • Added rootProject.name
    • Enabled typesafe project accessors feature

Insight 📝

  • Versions and gradle files were updated to match with template-compose

Proof Of Work 📹

App still builds and runs

output.mov

Summary by CodeRabbit

  • Build Configuration

    • Updated Gradle version to 8.0
    • Migrated to centralized dependency management using libs.versions.toml
    • Upgraded Java and Kotlin compiler compatibility to version 17
  • Dependency Management

    • Simplified dependency declarations
    • Consolidated test dependencies into bundles
    • Removed manual version tracking
  • Project Structure

    • Updated build scripts across modules
    • Standardized plugin and library references
    • Enabled build configuration generation
    • Introduced plugin and dependency resolution management settings

Copy link

coderabbitai bot commented Jan 10, 2025

Walkthrough

This pull request introduces a comprehensive refactoring of the build configuration across the sample-compose project. The changes primarily focus on modernizing the build system by transitioning to a version catalog approach using libs.versions.toml, upgrading the Java version from 11 to 17, and standardizing dependency management. The modifications span multiple configuration files, including build.gradle.kts, settings.gradle.kts, and the introduction of a new centralized version management file.

Changes

File Change Summary
sample-compose/app/build.gradle.kts Migrated to libs object for version management, added namespace, updated Java version to 17, enabled buildConfig
sample-compose/build.gradle.kts Replaced buildscript with plugin aliases, updated Detekt configuration
sample-compose/buildSrc/src/main/java/Configurations.kt Removed Module object
sample-compose/buildSrc/src/main/java/Versions.kt Completely removed version constants file
sample-compose/data/build.gradle.kts Updated plugin declarations, Java version, and dependency management
sample-compose/domain/build.gradle.kts Migrated to plugin aliases, upgraded Java version, simplified dependency declarations
sample-compose/gradle/libs.versions.toml New file introducing centralized version management
sample-compose/gradle/wrapper/gradle-wrapper.properties Updated Gradle wrapper to version 8.0
sample-compose/settings.gradle.kts Added plugin and dependency resolution management
.cicdtemplate/.github/workflows/bump_version.yml Updated version bumping workflow to target libs.versions.toml instead of Versions.kt
.cicdtemplate/.github/workflows/create_release_pull_request.yml Modified version extraction to use libs.versions.toml
.github/workflows/bump_version.yml Updated version bumping script to reflect new version management approach

Sequence Diagram

sequenceDiagram
    participant Dev as Developer
    participant BuildSystem as Gradle Build System
    participant VersionCatalog as libs.versions.toml
    participant Project as Project Modules

    Dev->>BuildSystem: Trigger Build
    BuildSystem->>VersionCatalog: Fetch Dependency Versions
    VersionCatalog-->>BuildSystem: Return Versions
    BuildSystem->>Project: Apply Configurations
    Project-->>BuildSystem: Compile and Build
Loading

Possibly related PRs

Suggested Reviewers

  • thawzintoe-ptut
  • luongvo
  • hoangnguyen92dn
  • minhnimble
  • eeeeaa
  • sleepylee
  • toby-thanathip
  • manh-t
  • Johnsonmaung

Poem

🐰 Gradle's dance of version delight,
Catalogs shine, configurations bright!
From Java 11 to 17's embrace,
Dependencies now find their place,
A rabbit's build, clean and tight! 🏗️


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.

@ryan-conway ryan-conway force-pushed the feature/586-migrate-to-build-version-catalog-part-2 branch from bb327d0 to 12471bd Compare January 10, 2025 08:06
@coderabbitai coderabbitai bot temporarily deployed to template-compose January 10, 2025 08:09 Inactive
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: 1

🔭 Outside diff range comments (1)
sample-compose/build.gradle.kts (1)

Fix detekt configuration file path

The detekt configuration file exists at sample-compose/detekt-config.yml, but the build script is looking for it at the wrong location. Update the config path in build.gradle.kts:

config = files("${project.projectDir}/detekt-config.yml")
🔗 Analysis chain

Line range hint 29-45: Verify detekt configuration completeness.

The detekt configuration looks good, but let's verify the configuration file:

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check if detekt config file exists and is not empty
if [ -f "detekt-config.yml" ]; then
    echo "detekt-config.yml exists"
    if [ -s "detekt-config.yml" ]; then
        echo "detekt-config.yml is not empty"
        head -n 5 "detekt-config.yml"
    else
        echo "WARNING: detekt-config.yml is empty"
    fi
else
    echo "WARNING: detekt-config.yml not found"
fi

Length of output: 113


Script:

#!/bin/bash
# Search for detekt configuration files
fd -t f -e yml -e yaml detekt

Length of output: 244

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 692a83c and 12471bd.

📒 Files selected for processing (9)
  • sample-compose/app/build.gradle.kts (3 hunks)
  • sample-compose/build.gradle.kts (3 hunks)
  • sample-compose/buildSrc/src/main/java/Configurations.kt (0 hunks)
  • sample-compose/buildSrc/src/main/java/Versions.kt (0 hunks)
  • sample-compose/data/build.gradle.kts (3 hunks)
  • sample-compose/domain/build.gradle.kts (1 hunks)
  • sample-compose/gradle/libs.versions.toml (1 hunks)
  • sample-compose/gradle/wrapper/gradle-wrapper.properties (1 hunks)
  • sample-compose/settings.gradle.kts (1 hunks)
💤 Files with no reviewable changes (2)
  • sample-compose/buildSrc/src/main/java/Versions.kt
  • sample-compose/buildSrc/src/main/java/Configurations.kt
⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: Review pull request
  • GitHub Check: Verify newproject script
  • GitHub Check: Run Detekt and unit tests
🔇 Additional comments (16)
sample-compose/settings.gradle.kts (3)

1-7: LGTM! Well-structured plugin repository configuration.

The repository order follows best practices (google -> mavenCentral -> gradlePluginPortal).


17-18: LGTM! Good setup for version catalog migration.

The TYPESAFE_PROJECT_ACCESSORS feature enables type-safe accessors for included builds and projects, which is perfect for version catalog usage.


8-15: Verify JitPack repository usage.

The JitPack repository is included, but let's verify if it's actually needed.

✅ Verification successful

JitPack repository is required

The repository is needed for resolving Chucker and Nimble Common dependencies defined in sample-compose/gradle/libs.versions.toml.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for dependencies that might be using JitPack
rg -g '*.{gradle,kts,toml}' 'com\.github\.'

Length of output: 2630

sample-compose/gradle/wrapper/gradle-wrapper.properties (1)

4-4: Verify Gradle 8.0 compatibility with project plugins.

The upgrade from Gradle 7.5 to 8.0 is significant. Let's verify plugin compatibility:

✅ Verification successful

Gradle 8.0 upgrade is compatible with project dependencies

All project dependencies and plugins are using recent versions that are compatible with Gradle 8.0. The Android Gradle Plugin (8.1.2), Kotlin (1.9.10), and other major dependencies are from versions that fully support Gradle 8.0.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for plugin versions in version catalog
rg -g 'libs.versions.toml' '^\s*[a-zA-Z-]+\s*=\s*"[^"]+"'

# Search for any TODO/FIXME comments that might indicate Gradle compatibility issues
rg -g '*.{gradle,kts}' 'TODO|FIXME|HACK|XXX'

Length of output: 4626

sample-compose/build.gradle.kts (1)

3-8: LGTM! Clean plugin declarations using version catalog.

The plugins are correctly declared using the version catalog with appropriate apply false flags.

sample-compose/domain/build.gradle.kts (2)

8-9: LGTM! Appropriate Java 17 configuration.

The Java version is correctly configured for both source and target compatibility.


13-16: LGTM! Clean dependency declarations using version catalog.

Dependencies are well-organized using the version catalog, and the test dependencies are nicely bundled.

sample-compose/data/build.gradle.kts (2)

8-9: LGTM! Proper Android configuration with namespace.

The Android configuration is correct with the namespace and SDK versions from the version catalog.


46-66: LGTM! Well-organized dependencies with clear API exposure.

Dependencies are properly organized using the version catalog. The use of api for Retrofit, OkHttp, and Moshi bundles is appropriate as these are meant to be exposed to dependent modules.

sample-compose/app/build.gradle.kts (4)

33-40: LGTM! Proper migration to version catalog for Android configuration

The changes correctly implement centralized version management using the version catalog, and the namespace declaration follows Android best practices.


122-164: LGTM! Well-structured dependency management using version catalog

Dependencies are properly migrated to use the version catalog and organized into logical bundles, improving maintainability.


76-81: Verify Java 17 compatibility across the project

The upgrade to Java 17 looks good, but let's verify that all modules are consistently using Java 17 to avoid compatibility issues.

✅ Verification successful

Java 17 configuration is consistent across all active modules

All active modules (sample-compose and template-compose) are properly configured to use Java 17 for source compatibility, target compatibility, and JVM target. The deprecated modules using older Java versions are in the deprecated/ directory and don't affect the active codebase.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check Java version settings across all Gradle build files
echo "Checking Java version configuration across all modules..."
rg -A 2 "JavaVersion\." --type kotlin

Length of output: 7175


85-91: Track hardcoded Compose compiler version

The hardcoded Compose compiler version should be addressed in issue #587. The addition of buildConfig = true is appropriate for the project requirements.

✅ Verification successful

Compose compiler version update is properly tracked

The hardcoded Compose compiler version (1.5.3) is acknowledged and being tracked in issue #587 "Migrate to latest Kotlin 2.1.0 and Compose Compiler plugin". The TODO comment serves its purpose as a temporary solution until the planned migration is completed.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check if issue #587 exists and is open
gh issue view 587 --json state,title

Length of output: 124

sample-compose/gradle/libs.versions.toml (3)

37-92: LGTM! Well-organized library declarations

The libraries section follows best practices with clear categorization and naming conventions.


93-131: LGTM! Effective dependency bundling

The bundles are logically organized and provide a clean way to manage related dependencies together.


133-140: LGTM! Complete plugin declarations

All necessary plugins are properly declared with consistent version management.

sample-compose/gradle/libs.versions.toml Outdated Show resolved Hide resolved
Copy link

github-actions bot commented Jan 10, 2025

8 Warnings
⚠️ Uh oh! Your project is under 80% coverage!
⚠️ template-compose/gradle/libs.versions.toml#L10 - A newer version of androidx.compose:compose-bom than 2023.09.02 is available: 2025.01.00
⚠️ template-compose/gradle/libs.versions.toml#L11 - A newer version of androidx.navigation:navigation-compose than 2.5.3 is available: 2.8.5
⚠️ template-compose/gradle/libs.versions.toml#L12 - A newer version of androidx.core:core-ktx than 1.10.1 is available: 1.15.0
⚠️ template-compose/gradle/libs.versions.toml#L13 - A newer version of androidx.datastore:datastore-preferences than 1.0.0 is available: 1.1.2
⚠️ template-compose/gradle/libs.versions.toml#L17 - A newer version of androidx.hilt:hilt-navigation-compose than 1.0.0 is available: 1.2.0
⚠️ template-compose/gradle/libs.versions.toml#L24 - A newer version of androidx.lifecycle:lifecycle-runtime-compose than 2.6.1 is available: 2.8.7
⚠️ template-compose/gradle/libs.versions.toml#L24 - A newer version of androidx.lifecycle:lifecycle-runtime-ktx than 2.6.1 is available: 2.8.7

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:

Configurations.kt
build.gradle.kts
build.gradle.kts
build.gradle.kts
build.gradle.kts
bump_version.yml
bump_version.yml
create_release_pull_request.yml
gradle-wrapper.properties
libs.versions.toml
settings.gradle.kts

Codebase cunningly covered by count Shroud 🧛

Generated by 🚫 Danger

@luongvo luongvo linked an issue Jan 14, 2025 that may be closed by this pull request
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.

The rest lgtm

sample-compose/app/build.gradle.kts Show resolved Hide resolved
sample-compose/app/build.gradle.kts Show resolved Hide resolved
sample-compose/app/build.gradle.kts Show resolved Hide resolved
sample-compose/app/build.gradle.kts Show resolved Hide resolved
sample-compose/gradle/libs.versions.toml Outdated Show resolved Hide resolved
@luongvo luongvo assigned luongvo and unassigned luongvo Jan 14, 2025
sample-compose/app/build.gradle.kts Show resolved Hide resolved
implementation("com.google.accompanist:accompanist-permissions:${Versions.ACCOMPANIST_VERSION}")
implementation("com.google.accompanist:accompanist-systemuicontroller:${Versions.ACCOMPANIST_VERSION}")
implementation(libs.accompanist.permissions)
implementation(libs.accompanist.systemUiController)
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we should create new issue to deprecate this lib. Now this officially support in androidx.activity 💁‍♂️ https://google.github.io/accompanist/systemuicontroller/

image

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: 1

🧹 Nitpick comments (1)
.github/workflows/bump_version.yml (1)

29-29: Improve version update robustness.

The version update pattern could be more robust to prevent accidental matches.

-perl -i -pe 's/androidVersionName =(.*)$/androidVersionName = "${{ github.event.inputs.newVersion }}"/g' sample-compose/gradle/libs.versions.toml
+perl -i -pe 's/^androidVersionName\s*=\s*"[^"]*"$/androidVersionName = "${{ github.event.inputs.newVersion }}"/g' sample-compose/gradle/libs.versions.toml
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 12471bd and fb7d65c.

📒 Files selected for processing (6)
  • .cicdtemplate/.github/workflows/bump_version.yml (1 hunks)
  • .cicdtemplate/.github/workflows/create_release_pull_request.yml (1 hunks)
  • .github/workflows/bump_version.yml (1 hunks)
  • sample-compose/app/build.gradle.kts (4 hunks)
  • sample-compose/build.gradle.kts (3 hunks)
  • sample-compose/gradle/libs.versions.toml (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • sample-compose/gradle/libs.versions.toml
  • sample-compose/app/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 (5)
sample-compose/build.gradle.kts (4)

3-11: Well-structured plugin declarations using version catalog!

The migration to version catalog syntax for plugin management is clean and follows Gradle best practices. The apply false pattern is correctly used for plugins that should only be applied to subprojects.


32-32: LGTM: Detekt version properly migrated to version catalog!

The Detekt tool version is now properly sourced from the version catalog, consistent with the migration objectives.


20-20: Verify Java 17 compatibility across modules.

The JVM target has been updated to Java 17, which aligns with the PR objectives.

Let's verify that all modules are consistently configured for Java 17:

✅ Verification successful

Java 17 configuration is consistent across modules

Both template-compose and sample-compose modules are correctly configured with Java 17 as their JVM target.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check Java version configuration across all Gradle build files
# Look for sourceCompatibility, targetCompatibility, and jvmTarget settings

rg -A 1 "sourceCompatibility|targetCompatibility|jvmTarget" **/*.gradle.kts

Length of output: 462


Line range hint 1-48: Verify complete migration of hardcoded versions.

Let's ensure no hardcoded versions remain in the build files:

✅ Verification successful

All versions successfully migrated in this file

The verification confirms that sample-compose/build.gradle.kts has successfully migrated all version declarations to the version catalog. While some hardcoded versions were found in other build files (kotlinCompilerExtensionVersion = "1.5.3"), they are outside the scope of this file review.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for potentially hardcoded versions in Gradle files
# Look for version numbers in quotes or direct version assignments

rg -g '*.gradle.kts' '(version\s*=\s*["\'][\d\.]+["\']|["\'][\d\.]+[-\.][\w\d\.-]+["\'])'

Length of output: 116


Script:

#!/bin/bash
# Search for version assignments and hardcoded versions in Gradle files
rg -g '*.gradle.kts' 'version\s*=\s*"[0-9]'
rg -g '*.gradle.kts' "version\s*=\s*'[0-9]"
rg -g '*.gradle.kts' '"[0-9]+\.[0-9]+\.[0-9]+"'
rg -g '*.gradle.kts' "'[0-9]+\.[0-9]+\.[0-9]+'"

Length of output: 372

.cicdtemplate/.github/workflows/create_release_pull_request.yml (1)

19-19: Verify the path and improve version extraction robustness.

The path to libs.versions.toml might need adjustment since this workflow is in the .cicdtemplate directory.

Consider making the version extraction more robust:

-run: echo "version=$(perl -nle 'print $1 if /androidVersionName = \"(.*)\"$/' gradle/libs.versions.toml)" >> $GITHUB_OUTPUT
+run: echo "version=$(perl -nle 'print $1 if /^androidVersionName\s*=\s*\"([^\"]+)\"/' gradle/libs.versions.toml)" >> $GITHUB_OUTPUT
✅ Verification successful

Template path needs to be relative to project root

The path gradle/libs.versions.toml is incorrect when running from .cicdtemplate but would work correctly when this workflow template is copied to the actual project root. This is the expected behavior for a template file.

The current implementation is correct for its intended use, as:

  1. This file is a template meant to be copied to the project root
  2. The path will resolve correctly in the final location
  3. The version extraction pattern works as verified in both existing TOML files
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Verify the existence and location of libs.versions.toml
fd --type f "libs.versions.toml$"

# Check if the version pattern exists in the found files
for file in $(fd --type f "libs.versions.toml$"); do
  echo "Checking $file:"
  grep -n "androidVersionName" "$file"
done

Length of output: 689


Script:

#!/bin/bash
# Check the workflow file content for project context
echo "Workflow file content:"
cat .cicdtemplate/.github/workflows/create_release_pull_request.yml

# Check directory structure relative to workflow
echo -e "\nDirectory structure from workflow location:"
cd .cicdtemplate && find . -type f -name "libs.versions.toml"

Length of output: 1080

@ryan-conway ryan-conway merged commit 304f3bf into develop Jan 27, 2025
5 of 6 checks passed
@ryan-conway ryan-conway deleted the feature/586-migrate-to-build-version-catalog-part-2 branch January 27, 2025 08:50
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
5 participants