Integrating a Version Catalog

Umang Chamaria
2 min readFeb 3, 2022

--

This article walks through the steps on how to integrate a published version catalog in your Gradle project.

It assumes that readers are familiar with Version Catalogs and does not touch upon the details of versions catalogs are. Refer to my article Version Catalogs in Gradle 7.0 to know about Version Catalogs.

Quick Recap

Version Catalog enables build authors to centralize the dependency coordinates (group, artifact, version) of their third-party dependencies in a conventional configuration file and declare the actual dependencies in a type-safe way. Declaring dependencies this way allows easy reuse of dependency coordinates in all modules, provides content assistance in the IDEs, and reduces the risk of typos. More importantly, it also provides a single location to change versions when upgrading a library.

We will walk through the steps of integrating a published catalog.

Refer to this article to learn more on how to publish a catalog.

Enable Version Catalog

Version catalog is a preview feature currently(in Gradle version 7.x.x) hence the feature needs to be enabled in your project’s settings.gradle(.kts) file as shown below.

Update: Version Catalog is stable in Gradle version 7.4, enabling feature is not required when using version 7.4 or above.

Adding the repository to fetch catalog

To download/fetch the published catalog you need to specify the repository from which the catalog should be fetched. To do so define the repository in which the catalog is published in the dependencyResolutionManagement block of the settings.gradle(.kts) file as shown below

Declaring catalog(s)

After adding the repository you need to add the catalog you want to use in your project and give it a name. To add the catalog define it in the dependencyResolutionManagement block of the settings.gradle(.kts) file as shown below

Sync and build the project after declaring the catalog.

Usage as dependency

Once the catalog is added to the project, add the required dependency for the module in the build.grale(.kts) file using a combination ofcatalog_name defined in the settings.gradle(.kts)andaliasdefined in the catalog as shown below.

Sync and build the project, once done you can use your library in your application.

Find the complete sample here. You can find the catalog referred to in the sample here.

--

--

Umang Chamaria
Umang Chamaria

No responses yet