---
title: 'Gradle Goodness: Set Project Version In Version Catalog'
updated: 2022-12-22 12:26:50Z
created: 2022-12-22 12:26:50Z
tags:
  - IT
  - Development/Gradle
source: https://blog.mrhaki.com/2022/12/gradle-goodness-set-project-version-in.html
---

### [Gradle Goodness: Set Project Version In Version Catalog](https://blog.mrhaki.com/2022/12/gradle-goodness-set-project-version-in.html)

The version catalog in Gradle is very useful to have one place in our project to define our project and plugin dependencies with their versions. But we can also use it to define our project version and then refer to that version from the version catalog in our build script file. That way the version catalog is our one place to look for everything related to a version. In the version catalog we have a `versions` section and there we can define a key with a version value. The name of the key could be our project or application name for example. We can use type safe accessors generated by Gradle in our build script to refer to that version.

In the following example build script written with Kotlin we see how we can refer to the version from the version catalog:

```kotlin
description = "Sample project for Gradle version catalog"
version = libs.versions.app.version.get()
tasks {
    register("projectVersion") {
        doLast {
            println("Project version: " + version)
        }
    }
}
```

And the version catalog is defined in the following file:

```properties
[versions]
app-version = "2.0.1"
```

When we run the task `projectVersion` we see our project version in the output:

```shell
$ gradle projectVersion
Task :projectVersion

Project version: 2.0.1

BUILD SUCCESSFUL in 831ms

1 actionable task: 1 executed
$
```

Written with Gradle 7.6.