We are using Gradle's axion-release plugin for release & version management.
If current commit is tagged commit, project has a release version( i.e., 0.1.0).
If there were any commits after last tag, project is in SNAPSHOT version( i.e., 0.1.1-SNAPSHOT).
axion-release follows the structure of git, only knows about tags on given branch.
Usage
first time generating a new library project
gradleinit--typekotlin-library--dslkotlin
Options for all gradle commands: -D or --system-prop, -P or --project-prop, -m or --dry-run
Check Task Dependencies With a Dry Run with dryRun: -m or --dry-run i.e., gradle publish -m
Version
display computed version
gradlecVgradlecurrentVersion# to get version # as plain textexport VERSION=$(gradlecV-q-Prelease.quiet)echo $VERSION
Verification
gradletestgradlejacocoTestReportgradlejacocoTestCoverageVerification# gotcha: jacoco reports need to be generated before any of the sonar taskgradlecheckgradlesonarqube
dependency-check
Software Composition Analysis (SCA) tool that attempts to detect publicly disclosed vulnerabilities contained within a project’s dependencies.
Note: Cross-module tests are not supported in reports and validation yet. For each test, only the classpath belonging to the current module is taken.
gradlekoverMergedReport-xtest# Generates code coverage report for all enabled test tasks in all projects.gradle koverMergedVerify # Verifies code coverage metrics of all projects based on specified rules. Always executes before `check` task.
gradlekoverReport# Executes both koverXmlReport and koverHtmlReport tasks for one project.gradlekoverVerify# Verifies code coverage metrics of one project based on specified rules.
Spotless tasks
# spotlessCheck - Checks that sourcecode satisfies formatting steps.gradlespotlessCheck# spotlessApply - Applies code formatting steps to sourcecode in-place.gradlespotlessApply
Quarkus tasks
# addExtension - Adds Quarkus extensions specified by the user to the project.gradle:services:greeting:addExtension--extensions="health,metrics,openapi"gradle:services:greeting:addExtension--extensions="hibernate-validator"gradle:services:greeting:addExtension--extensions="jdbc,agroal,non-exist-ent"# buildNative - Building a native imagegradle:services:greeting:buildNativegradle:services:greeting:testNative# generateConfig - Generates an example config file# listExtensions - Lists the available quarkus extensionsgradle:services:greeting:listExtensions# quarkusBuild - Quarkus builds a runner jar based on the build jar# quarkusDev - Development mode: enables hot deployment with background compilationgradle:services:greeting:quarkusDev-Dsuspend-Ddebug# quarkusTestConfig - Sets the necessary system properties for the Quarkus tests to run.
Docker Compose
start/stop dependent services for your app
# start local redisgradleredisComposeUp# stop local redis before restart againgradleredisComposeDown# copy container logs to `build/containers-logs`gradleredisComposeLogs
Affected Module Detector (AMD)
The detector allows for three options for affected modules:
Changed Projects: These are projects which had files changed within them – enabled with -Paffected_module_detector.changedProjects)
Dependent Projects: These are projects which are dependent on projects which had changes within them enabled with -Paffected_module_detector.dependentProjects)
All Affected Projects: This is the union of Changed Projects and Dependent Projects (this is the default configuration)
# Running All Affected Projects (Changed Projects + Dependent Projects)gradlerunAffectedUnitTests-Paffected_module_detector.enable# Running All Changed ProjectsgradlerunAffectedUnitTests-Paffected_module_detector.enable-Paffected_module_detector.changedProjects# Running All Dependent ProjectsgradlerunAffectedUnitTests-Paffected_module_detector.enable-Paffected_module_detector.dependentProjects# runs connected testsgradlerunAffectedAndroidTests-Paffected_module_detector.enable# assembles but does not run on device tests, useful when working with device labsgradleassembleAffectedAndroidTests-Paffected_module_detector.enable
# dryRungradlerelease-Prelease.dryRun# disable all checks for current releasegradlerelease-Prelease.disableChecks-Prelease.dryRun# real releasegradlerelease-Prelease.customUsername=sxc460-Prelease.customPassword=# bump Minor Version : 0.1.0 -> 0.2.0gradlemarkNextVersion-Prelease.incrementer=incrementMinor-Prelease.dryRun# in CI enveroment gradlerelease-Prelease.disableChecks-Prelease.pushTagsOnly-xtest--profile# if you want to manually set version with Jenkins paramsgradlecreateRelease-Prelease.disableChecks-Prelease.versionIncrementer=incrementMajor-Prelease.dryRungradlemarkNextVersion-Prelease.disableChecks-Prelease.incrementer=incrementMajor-Prelease.dryRun
Changelog
With every release, run git-chglog
# first timegit-chglog--init# on release branch, generate CHANGELOG.md and commit before merging back to develop & main.git-chglog-c.github/chglog/config.yml-oCHANGELOG.mdgit-chglog-c.github/chglog/config.yml-oCHANGELOG.md--next-tag2.0.0
# prints the last published version and calculated next versiongradlechangelogPrint# throws an error if the changelog is not formatted according to your rulesgradlechangelogCheck## Update the changelog, commit, push# updates the changelog on disk with the next version and the current UTC dategradlechangelogBump-Prelease=true# commits the changelog, tags, and pushesgradlechangelogPush
Publish
publish after release
gradlepublish# skip tests in CIgradlepublish-xtest--profilegradlebuildpublish-Prelease.forceSnapshotgradlebuildpublish-Prelease.forceVersion=3.0.0# set `CI=true` to publish from laptopCI=truegradlepublish-Prelease.forceSnapshotCI=true GITHUB_USER=xmlking GITHUB_TOKEN=<GITHUB_PACKAGES_TOKEN>gradlepublish
Docker
# Build an image tarball,# then you can load with `docker load --input build/jib-image.tar`gradlejibBuildTar# Build and publish docker imagegradlejib# Build image locally useing your Docker daemon (on publish)gradlejibDockerBuild
local testing
pull a remote image and locally use it as base image
# pull base image firstdockerpullgcr.io/distroless/java:11# use local docker image as base, build image only (on publish)gradlejibDockerBuild-PbaseDockerImage=docker://gcr.io/distroless/java:11# you can run your local docker imagedockerrun-itxmlking/micro-apps-demo:1.6.5-SNAPSHOT
# Report dependenciesgradledependencyUpdates-Drevision=release-DoutputFormatter=json,xml# Update dependencies, `dependsOn dependencyUpdates`# Creating a libs.versions.toml file, If you don't have a catalog file yetgradleversionCatalogUpdate--create# Updating the libs.versions.toml filegradleversionCatalogUpdategradleversionCatalogUpdate--interactive
Gradle
# upgrade gradlew# upgrade project gradle versiongradlewrapper--distribution-typeall# gradle wrapper --gradle-version=7.0# gradle daemon status gradle--statusgradle--stop# show dependenciesgradleclassifier:dependenciesgradleclassifier:dependencyInsight--dependencyspring-messaging# refresh dependenciesgradlebuild-xtest--refresh-dependencies# viewing and debugging dependenciesgradle-q:services:greeting:dependencyInsight--dependencyorg.ow2.asm:asm--configurationtestCompileClasspath# display version gradlecV
Maven
Remove a local built dependency from local-maven-repository