Published on

Version Catalog Documentation

Authors

The [Version Catalog] provides a shared list of dependency versions for a KMM project.

Contents

The catalog VERSION_NAME is defined in [gradle.properties].

VERSION_NAME = 0.1.0

Dependency and version definitions are found in the [root build.gradle.kts file]. The catalog consists of three sections:

1. Versions

Version definitions can be shared by multiple dependencies. Definitions consist of a tag and a semantic version string:


        version("android", "7.3.1")

2. Plugins

Defines an alias, id, and version definition for each plugin dependency. Version definitions should always be declared as a versionRef, referencing a version defined in Section 1. Multiple related dependencies may reference the same versionRef.


        plugin("androidApplication", "com.android.application").versionRef("android")
        plugin("androidLibrary", "com.android.library").versionRef("android")
        ...

3. Libraries

Defines an alias, id, and version definition for each library dependency. Version definitions should always be declared as a versionRef, referencing a version defined in Section 1. Multiple related dependencies may reference the same versionRef.


        library("<library-name-A>", "com.<company>.auth", "auth-shared").versionRef("<library-name>")
        library("<library-name-B>", "com.<company>.auth", "auth-android").versionRef("<library-name>")
        ...

Usage

KMM projects can use the version catalog by adding the versionCatalogs block to the dependencyResolutionManagement section of settings.gradle.kts:

dependencyResolutionManagement {
    versionCatalogs {
        create("libs") {
            from("com.<company>.version-catalog:version-catalog:0.1.0")
        }
    }
}

Dependencies can the be declared by referencing the version catalog via libs:

plugins {
    with(libs.plugins){
        alias(androidLibrary)
        alias(kotlinMultiplatform)
        ...
    }
}

...

dependencies {
    with(libs){
        implementation(kotlinxCoroutines)
        ...
    }
}

Version Override

To override a version defined in the version catalog with a new value, add the new version definition in settings.gradle.kts:

dependencyResolutionManagement {
    versionCatalogs {
        create("libs") {
            from("com.<company>.version-catalog:version-catalog:0.1.0")
            version("<library-name>", "1.2.3-local") // Override's the library's version with "1.2.3-local"
        }
    }
}