Publishing Version Catalog
This article assumes that readers are familiar with Version Catalogs and does not touch upon what versions catalogs are. Refer to my article Version Catalogs in Gradle 7.0 to know about Version Catalogs.
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.
One of the big advantages of a Version Catalog is that it can be shared and published across various projects.
We will walk through the steps of publishing a catalog to maven.
Note: This does not cover the process of creating and setting up a publishing account. Refer to the official documentation to create and set up an account if you don’t have one.
Create a Gradle project
Create a basic Gradle project using
gradle init Kotlin as the DSL language. You can use a Groovy DSL as well, for the purpose of this walkthrough we are using Kotlin DSL.
Add the following code in the generated
Applying the version catalog plugin
Gradle offers a version catalog plugin, which offers the ability to declare, then publish a catalog.
Defining a catalog
Add dependency coordinates in the catalog block with an alias name
Configuring Publishing Metadata
To publish the catalog to maven requires multiple things: components to be published, artifact meta-data, POM meta-data, licensing details, repository, and developer information, credentials publishing URL, etc.
To publish you need to add the credentials to the environment. You can add your credentials in a
gradle.properties file in either the Gradle’s installation directory of your system or create a
gradle.properties file in your project(do not check in this file into version control for obvious reasons). Make sure the variable name used in the file is the same as what you declare in the script. In the above example, the variables should be
The properties file would look like following
All artifacts uploaded to maven have to be signed. To sign the catalog add the below block to your script. Make sure you have the signing key metadata in your
Uploading to Maven
To upload the catalog to maven run the below command in the project directory
Once the artifact is successfully uploaded log in to your sonatype account and publish the staged repository.