Skip to content
BETAGuardrails are in beta. The library, the configuration format and the CLI command can still change.

Guardrails / kotlin

Gradle dependencies are locked

kotlin/dependencies-locked@v1

The Gradle build commits the lock files that resolve its dependencies, so the same commit builds from the same versions.

Idkotlin/dependencies-locked
Versionv1
Categorykotlin
Default severitywarning
Interpreterpython3
Timeout30 seconds
Violations tolerated0
Collectsgradle

Collectors

This guardrail gathers nothing itself. It depends on the collectors below, which the CLI runs once per build before any check, and reads what they found out of GUARDRAIL_FACTS. A collector that collects nothing skips this guardrail rather than failing it.

CollectorGathersInputs it is given
gradleThe Gradle build in the project directory: its settings and manifest, every included project, the wrapper and the distribution it pins, the version catalog, and every dependency the build files declare or the lock files resolve, with the versions its platforms supply.projectDir

The inputs above are this guardrail's own, passed straight through. Configuring one in buildnote.json changes what is collected, and two guardrails configured the same way share the one collection.

Configuration

json
{
  "guardrails": {
      "failOn": "error",
      "comment": true,
      "checks": [
          {
              "use": "kotlin/dependencies-locked@v1",
              "severity": "warning",
              "with": {
                  "projectDir": ".",
                  "minLockfiles": "1"
              },
              "exemptions": []
          }
      ]
  }
}

Inputs

InputDescriptionDefaultEnvironment variable
projectDirDirectory holding the project, relative to the directory the CLI runs in..GUARDRAIL_INPUT_PROJECTDIR
minLockfilesFewest lock files the build must commit.1GUARDRAIL_INPUT_MINLOCKFILES

How to fix

Turn locking on for every configuration and write the lock files:

kotlin
dependencyLocking {
    lockAllConfigurations()
}
bash
./gradlew dependencies --write-locks

Commit the gradle.lockfile files it writes. Without them a dynamic version, or a transitive dependency whose own range moved, resolves differently on a rebuild of the same commit, and the build that shipped is not the build that was reviewed.

More in kotlin

  • kotlin/build-manifest. The project declares a recognised build manifest, so the build is reproducible and tooling can find it.
  • kotlin/gradle-wrapper. A Gradle project commits gradlew and the wrapper properties that pin the Gradle version.
  • kotlin/kotlin-version-pinned. The Kotlin compiler version is declared in the build, and is no older than the configured floor.

All 4 kotlin guardrails

Buildnote Limited
Registered in England and Wales, Reg: 16140412