Tools for creating new versions through CI processes. It is specifically designed for GitLab CI. This tool is intended for two specific use cases:
To remove the -SNAPSHOT suffix from the build.gradle file and create a new git commit. In the simplest case, this looks like this in .gitlab-ci.yml:
stages:
- deploy
- release
.gradle_template:
image: gradle:8.4-jdk21-jammy
git:release:
extends: .gradle_template
stage: release
rules:
- when: manual
script:
# Create a new commit on the main branch
- ./gradlew configureReleaseBot
switchToMainAndCatchItUp
removeSnapshotFromVersion
updateVersionNumberInReadme
gitCommitForRelease
createGitTagForVersion
gitPushThe second use case is creating a new commit on the development branch with the next higher patch number and a snapshot suffix (so release 2.0.0 is followed by 2.0.1-SNAPSHOT). This is done via
git:preparesnapshot:
extends: .gradle_template
stage: release
rules:
- if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
script:
# Only perform the branching when this is not a SNAPSHOT version on the main branch.
- if [[ ($(./gradlew properties | grep version) =~ "SNAPSHOT") ]]; then exit 0; fi
# Create a new commit on the development branch for the next version
- ./gradlew configureReleaseBot
switchToDevelopmentAndCatchItUp
prepareNextSnapshotVersion
updateVersionNumberInReadme
gitCommitForSnapshot
gitPushThe release is then done by manually running the job in the development pipeline.
The if line aborts CI execution depending on whether it refers to a snapshot or non-snapshot version.
A complete minimal example is provided by .gitlab-ci.yml.
This plugin is simply listed together with the other Gradle plugins.
plugins {
...
id 'gmbh.pagina.tools.gradle.release' version '1.3.0'
}This plugin can be obtained from the Gradle Plugin Portal.
Snapshot-versions are available in the pagina Artifactory.
This is not publicly available.
To publish packages there, $ARTIFACTORY_USER and $ARTIFACTORY_PASSWORD must be set as environment variables.
For version number replacement, an additional configuration option must be specified. See here.
The following tasks are provided by this tool:
Sets up the release bot SSH keys and prepares git branches so they can be pushed.
Removes the -SNAPSHOT suffix from build.gradle.
Increases the patch version in build.gradle and adds the -SNAPSHOT suffix. 2.0.0 becomes 2.0.1-SNAPSHOT.
If the README contains a line that explains how the plugin is used (as shown here), then the version number there is replaced with the current one from build.gradle.
To know for which plugin the version number should be replaced, the plugin ID must be specified in build.gradle as follows:
updateVersionNumberInReadme {
pluginId = "gmbh.pagina.tools.gradle.release"
// naturally, use the corresponding ID here instead of the one for this plugin.
}By default, <group>.<project-name> is assumed here, so this block is not strictly required.
There is also the readmeName option, which has README.md as the default and therefore probably never needs to be changed.
Creates a git commit with a message indicating that this is the release of the version.
Creates a git commit with a message indicating that this is the next snapshot version.
Switches to the main branch and fast-forwards it to the state of the current branch.
The main branch is determined by the CI_DEFAULT_BRANCH variable, which is set by GitLab CI to the default branch of the repository (usually main or master).
Switches to the development branch and fast-forwards it to the state of the main branch.
The main branch is determined by the CI_DEFAULT_BRANCH variable, which is set by GitLab CI to the default branch of the repository (usually main or master).
Creates a Git tag for the version currently set in build.gradle.
Pushes all branches and tags to the server.
- Handling when the development branch does not exist. It is the GitLab default for repositories that when a merge request is completed, the source branch is deleted.