Skip to content

gradle.star

Bump Gradle dependencies, version catalog entries and the Gradle wrapper.

Edits are line-based, so comments and formatting in build scripts and libs.versions.toml stay as they were.

load("@fleet//gradle.star", "build_files", "set_dependency", "wrapper_version", "set_wrapper_version", "set_plugin", "set_kotlin_version")
Function What it does
build_files Lists the build scripts and version catalogs.
set_dependency Sets a library's version wherever the build declares it.
wrapper_version Reads the Gradle version the wrapper downloads.
set_wrapper_version Points the Gradle wrapper at a new version, never lowering it.
set_plugin Sets the version of a Gradle plugin wherever the build applies or declares it.
set_kotlin_version Moves every Kotlin Gradle plugin, and the Kotlin standard library, to one version.

build_files

build_files(repo)

Lists the build scripts and version catalogs.

Arguments

Name Description
repo The repo passed to change(repo).

Returns: The sorted paths of every build.gradle, build.gradle.kts, settings.gradle(.kts) and *.versions.toml outside build directories.

Example

build_files(repo)
# returns ["app/build.gradle", "build.gradle.kts", "gradle/libs.versions.toml"]

build.gradle.kts

plugins { java }

app/build.gradle

apply plugin: 'java'

gradle/libs.versions.toml

[versions]

build/tmp/build.gradle

generated

Source

set_dependency

set_dependency(repo, module, version)

Sets a library's version wherever the build declares it.

A newer version already there is kept, so a campaign never lowers one.

Covers string coordinates in build scripts ("group:name:1.0", in Groovy or Kotlin), and in version catalogs both alias = "group:name:1.0" and { module = "group:name", version = "1.0" }, including a version.ref that points into [versions]. Coordinates whose version is a variable ("group:name:$v") are left alone.

Arguments

Name Description
repo The repo passed to change(repo).
module The library as group:name.
version The new version.

Returns: The list of paths that changed.

Example

set_dependency(repo, "com.squareup.okhttp3:okhttp", "4.12.0")
set_dependency(repo, "com.fasterxml.jackson.core:jackson-databind", "2.17.2")
# returns ["gradle/libs.versions.toml"]

build.gradle.kts

dependencies {
    implementation("com.squareup.okhttp3:okhttp:4.11.0")
    testImplementation(libs.junit)
}

gradle/libs.versions.toml

[versions]
jackson = "2.15.2"

[libraries]
jackson-databind = { module = "com.fasterxml.jackson.core:jackson-databind", version.ref = "jackson" }

build.gradle.kts

dependencies {
    implementation("com.squareup.okhttp3:okhttp:4.12.0")
    testImplementation(libs.junit)
}

gradle/libs.versions.toml

[versions]
jackson = "2.17.2"

[libraries]
jackson-databind = { module = "com.fasterxml.jackson.core:jackson-databind", version.ref = "jackson" }

Used in: jvm-dependency-bump

Source

wrapper_version

wrapper_version(repo)

Reads the Gradle version the wrapper downloads.

Arguments

Name Description
repo The repo passed to change(repo).

Returns: The version, such as 8.5, or None when the repo has no wrapper.

Example

wrapper_version(repo)
# returns "8.5"

gradle/wrapper/gradle-wrapper.properties

distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip

Source

set_wrapper_version

set_wrapper_version(repo, version, sha256 = None)

Points the Gradle wrapper at a new version, never lowering it.

Only gradle-wrapper.properties changes; Gradle downloads the new distribution on the next run. When the file pins a checksum with distributionSha256Sum, pass the new distribution's sha256 from https://gradle.org/release-checksums/, or the run fails rather than leave a checksum that no longer matches.

Arguments

Name Description
repo The repo passed to change(repo).
version The Gradle version, such as 8.10.2.
sha256 The SHA-256 of the new distribution zip, for wrappers that verify it, or a dict of it by distribution type (bin, all), so one campaign covers both.

Returns: True when the file changed.

Example

set_wrapper_version(repo, "8.10.2")
# returns True

gradle/wrapper/gradle-wrapper.properties

distributionBase=GRADLE_USER_HOME
distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip

gradle/wrapper/gradle-wrapper.properties

distributionBase=GRADLE_USER_HOME
distributionUrl=https\://services.gradle.org/distributions/gradle-8.10.2-bin.zip

Used in: gradle-wrapper-bump

Source

set_plugin

set_plugin(repo, plugin, version)

Sets the version of a Gradle plugin wherever the build applies or declares it.

A newer version already there is kept, so a campaign never lowers one.

Covers id 'x' version 'v' (Groovy), id("x") version "v" (Kotlin), and version catalog [plugins] entries, written as { id = "x", version = "v" }, { id = "x", version.ref = "key" } (setting [versions] instead) or "x:v". For Kotlin plugins, kotlin("jvm") version "v" matches org.jetbrains.kotlin.jvm.

Arguments

Name Description
repo The repo passed to change(repo).
plugin The plugin ID, such as com.android.application.
version The new version.

Returns: The list of paths that changed.

Example

set_plugin(repo, "org.jetbrains.kotlin.android", "2.0.21")
set_plugin(repo, "com.android.application", "8.7.2")
# returns ["build.gradle.kts", "gradle/libs.versions.toml"]

build.gradle.kts

plugins {
    id("com.android.application") version "8.1.4" apply false
    kotlin("android") version "1.9.10" apply false
}

gradle/libs.versions.toml

[versions]
agp = "8.1.4"

[plugins]
android-application = { id = "com.android.application", version.ref = "agp" }

build.gradle.kts

plugins {
    id("com.android.application") version "8.7.2" apply false
    kotlin("android") version "2.0.21" apply false
}

gradle/libs.versions.toml

[versions]
agp = "8.7.2"

[plugins]
android-application = { id = "com.android.application", version.ref = "agp" }

Source

set_kotlin_version

set_kotlin_version(repo, version)

Moves every Kotlin Gradle plugin, and the Kotlin standard library, to one version.

A newer version already there is kept, so a campaign never lowers one.

Sets every org.jetbrains.kotlin.* plugin a build applies (in either DSL or a version catalog), the kotlin-gradle-plugin classpath dependency of older builds, a kotlin or kotlin_version entry in [versions], and ext.kotlin_version in Groovy builds.

Arguments

Name Description
repo The repo passed to change(repo).
version The Kotlin version, such as 2.0.21.

Returns: The list of paths that changed.

Example

set_kotlin_version(repo, "2.0.21")
# returns ["build.gradle"]

build.gradle

buildscript {
    ext.kotlin_version = '1.8.22'
    dependencies {
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
    }
}

build.gradle

buildscript {
    ext.kotlin_version = '2.0.21'
    dependencies {
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
    }
}

Source