Interview Prep/Build Tools (Java, Node.js, Python, .NET)/Java builds (Maven, Gradle, JAR, WAR)

How should build artifacts be versioned in a CI/CD pipeline?

IntermediateConceptJava builds (Maven, Gradle, JAR, WAR)
Answer

Short answer

Every build should produce a unique, traceable, immutable version — usually semantic version + build metadata such as the Git commit SHA (e.g. 1.4.0-9f2c1ab or 1.4.0+build.512). That version is used for the JAR, the Docker image tag and the deployment, so you can always trace what's running back to the exact commit.

Common schemes

Scheme Example Used for
SemVer release 1.4.0 Tagged releases (git tag v1.4.0)
SemVer + SHA 1.4.0-9f2c1ab Every main-branch build
Date-based 2026.11.26-512 Continuous delivery apps
Git SHA only 9f2c1ab Docker image tags in GitOps

Example in a pipeline

VERSION="1.4.$GITHUB_RUN_NUMBER-${GITHUB_SHA::7}"
mvn -B versions:set -DnewVersion=$VERSION
mvn -B deploy
docker build -t registry/orders:$VERSION .

Rules

  • Never deploy latest — you can't tell what it contains or roll back to it.
  • Never overwrite a published version.
  • Build once, promote the same version through environments.

What to say in the interview

"Each build gets a unique version combining semver with the run number or commit SHA, applied to the artifact and the image tag. Versions are immutable, we never deploy latest, and the same version is promoted from dev to prod for full traceability."

All Build Tools (Java, Node.js, Python, .NET) questions Roadmap: Java apps: Maven, Gradle, JAR & WAR

More on Java builds (Maven, Gradle, JAR, WAR)