GradleのVersion CatalogとRenovateでAndroidアプリのライブラリアップデートを管理する
個人アプリのライブラリアップデートがしんどくなってきてちらほら見かけていたRenovateを試してみた
Renovateの設定
GithubであればRenovateのアプリを追加すれば簡単に初期設定が完了する。
初期設定が完了するとrenovate.jsonというファイルが作成されるPRが作られる。
自動マージやスケジューリングやグルーピングなどいろんな設定があるが一旦下記のようにしてみた。自動マージはテストライブラリにとどめている。
{ "extends": [ "config:base", ":timezone(Asia/Tokyo)" ], "packageRules": [ { "groupName": "Jetpack Compose", "matchPackagePatterns": [ "^androidx\\.compose:", "^androidx\\.compose\\.animation:", "^androidx\\.compose\\.compiler:", "^androidx\\.compose\\.foundation:", "^androidx\\.compose\\.material:", "^androidx\\.compose\\.runtime:", "^androidx\\.compose\\.ui:" ] }, { "groupName": "androidx.activity", "matchPackagePatterns": [ "^androidx\\.activity:" ] }, { "groupName": "androidx.lifecycle", "matchPackagePatterns": [ "^androidx\\.lifecycle:" ] }, { "groupName": "androidx.test", "matchPackagePatterns": [ "^androidx\\.test:", "^androidx\\.test\\.ext:", "^androidx\\.test\\.espresso:" ], "automerge": true, "major": { "automerge": false } }, { "groupName": "kotlinx.coroutines", "matchPackagePatterns": [ "^org\\.jetbrains\\.kotlinx:kotlinx-coroutines" ] } ] }
Renovateが対応しているGradleのVersion Catalogに移行する
自分のプロジェクトではモジュール間でバージョンを揃えるためにトップのbuild.gradleにextでバージョンを設定していたが、Renovateはextで設定したバージョンは検知してくれなかった。
Renovateが検知できるライブラリの指定方法はいくつかある。
- build.gradle/build.gradle.kts files in the root of the repository
- .gradle/.gradle.kts files in a subdirectory as multi-project configurations
- dependencies whose version is defined in a *.properties file
- .versions.toml files in any directory or .toml files inside the gradle directory (Gradle Version Catalogs docs)
せっかくなのでこちらも気になっていたGradleのVersion Catalogに移行してみた。
GradleのVersion Catalog
Version CatalogはGradleの7.0から使える機能でGradle公式でバージョン管理ができるようになった
いろんな設定方法があるがRenovateはtomlファイルを作らないと検知してくれないのでlibs.versions.tomlファイルを作る方式で設定する。
[versions] jetpack_compose = "1.1.0" [libraries] compose-ui = { module = "androidx.compose.ui:ui", version.ref = "jetpack_compose" } compose-ui-tooling = { module = "androidx.compose.ui:ui-tooling", version.ref = "jetpack_compose" } compose-foundation = { module = "androidx.compose.foundation:foundation", version.ref = "jetpack_compose" } compose-material = { module = "androidx.compose.material:material", version.ref = "jetpack_compose" } compose-material-icons = { module = "androidx.compose.material:material-icons-core", version.ref = "jetpack_compose" } compose-material-icons-extended = { module = "androidx.compose.material:material-icons-extended", version.ref = "jetpack_compose" } compose-livedata = { module = "androidx.compose.runtime:runtime-livedata", version.ref = "jetpack_compose" } [bundles] compose = ["compose-ui", "compose-ui-tooling", "compose-foundation", "compose-material", "compose-material-icons", "compose-material-icons-extended", "compose-livedata"]
のように設定すると各build.gradleで libs.compose.ui
のように使える(ハイフンはドット区切りになる)。Jetpack Composeのようにまとめて使う場合が多いのはbundlesに設定すると libs.bundles.compose
のようにまとめて使える。
おわりに
Renovateは自動でPRを作ってくれるのはもちろん、リリースノートへのリンクやダッシュボードからのまとめてのrebaseなど効率よくライブラリアップデートができるようになっていて体験がよかった。いつか有料になりそうな気もするが無料の間はしばらく使ってみようと思う。