HomeAndroidAutomating dependency updates in a Compose mission | by Jose Alcérreca |...

Automating dependency updates in a Compose mission | by Jose Alcérreca | Android Builders | Mar, 2023


We advocate utilizing the newest libraries in your Android tasks as they’ve extra options and bug fixes. Nevertheless, bumping variations and fixing breaking adjustments could be an intricate course of, particularly when you attempt to repair many on the similar time. Automating this course of reduces errors however there are some issues to take note of when you use Compose.

As a result of upkeep can really feel like a thankless activity, it is best to attempt to automate as a lot of it as doable by:

  • Having a Steady Integration system to make sure that the code is consistently in a wholesome state.
  • Working automated exams to offer your workforce quick suggestions on how the app behaves after adjustments, catching regressions.
  • Automating the technology of updates, which is what this publish is about.

Bumping variations usually means opening the construct file the place you outline your dependencies or their variations after which going to both Google’s Maven repository or Maven Central to determine which one it is best to use. Often:

  • If you’re utilizing a secure model of a library, you often bump to the newest secure (e.g. 2.5.0 to 2.6.2).
  • In the event you’re on an unstable observe, you select both a newer secure model, or a newer unstable artifact of the identical model (e.g. 1.2.0-alpha05 would transfer to 1.2.0-beta01 or 1.2.1, however to not 1.2.2-alpha01).
  • If there’s a brand new main model of a library, there are most likely breaking adjustments and it is best to try this replace in its personal PR (e.g. 1.2.5 to 2.0.1).

Android Studio supplies hints with proposed library updates (and Model Catalogs help is coming in Android Studio Giraffe!) however you can too automate this course of in two other ways:

For Structure samples, we desire to not pollute construct information with plugins that builders won’t use, so we went with an exterior service. In our explicit case we’re utilizing Renovate as a result of Dependabot doesn’t help dependency grouping, which is essential when you use Compose.

The model bumping algorithm described above is straightforward, nevertheless it doesn’t all the time work with the default setup. For instance, automated updates may fail when utilizing Compose dependencies. The reason being that the Compose Compiler has a strict mapping to particular variations of Kotlin. You will discover the desk right here. Sometimes, these two dependencies aren’t launched on the similar time, so there’s a delay of a number of days between Kotlin’s new model and the corresponding Compose Compiler. This implies that you could’t replace Kotlin to the newest model if the Compose Compiler hasn’t been launched but.

With Renovate we group all updates in a single PR utilizing the group:all directive (see it in motion in one in all our configuration information). This makes upkeep even simpler as a result of we solely must approve one PR each week. Nevertheless, doing which means each time there’s a Kotlin launch, our Compose mission would break till the Compose compiler is launched. This wouldn’t be an enormous deal if it wasn’t for the truth that when your construct is damaged the remainder of the updates must wait.

To repair this, you possibly can group updates collectively. The concept is to separate the Kotlin updates from the opposite adjustments so as to preserve updating your different dependencies.

In Renovate, that’s executed with packageRules:

These guidelines create a bunch identify referred to as “kotlin” and add Kotlin itself, the Compose compiler and KSP.

With this, Renovate will generate two totally different PRs per department. One for the “kotlin” group, and the opposite for the remainder of the dependencies.

The Kotlin PR solely accommodates updates associated to Kotlin as anticipated:

Instance PR solely updating Kotlin dependencies

Because of this when a brand new model of Kotlin is on the market, this PR will likely be created and its construct will initially fail till the Compose Compiler is on the market. Having a failing PR for some time won’t be ideally suited and there are characteristic requests that appear to deal with an analogous downside, however I personally don’t thoughts it as a reminder {that a} new Kotlin model is coming.

An necessary characteristic of Renovate is that when you add a decide to one in all its PRs, the bot will cease making an attempt to replace it, letting you make tweaks. The day-to-day is configured in a intelligent dashboard (see instance) and it has a large set of configuration choices.

Renovate has been working flawlessly and we’re including it to extra Structure repositories. Nevertheless, I believe that the documentation may gain advantage from extra use-case based mostly examples as I discovered myself relying a bit an excessive amount of on Stackoverflow and snippets discovered on Github points.

In conclusion, establishing a system to maintain your dependencies contemporary is a good funding. It doesn’t matter which system you employ so long as it reduces the upkeep burden of your tasks so that you could be extra productive… or go dwelling early.

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments