Skip to main content

Use POM Version

Use the Maven project's project.version as the OneDev build version.

  1. Add Checkout Code as the first step so pom.xml is available in the job working directory.

  2. Add an Execute Commands step named Detect build version. Use an image with Maven and a suitable JDK, such as maven:3.9-eclipse-temurin-17, and the POSIX Compatible Shell interpreter. Run:

    set -eu
    mvn -B -ntp org.apache.maven.plugins:maven-help-plugin:3.5.1:evaluate \
    -Dexpression=project.version -q -DforceStdout -Doutput=buildVersion
    test -s buildVersion
    cat buildVersion

    Maven may need to download plugins and dependencies on the first run. The command writes the version directly to buildVersion; set -e stops the step if Maven fails, and test -s verifies that the output file is not empty.

    Extracting the Maven project version

  3. Add Set Build Version after the command step and set Build Version to @file:buildVersion@. Keep the step condition Successful so it only runs after successful extraction.

    Setting the build version from the generated file

  4. Commit the build specification and run the job. Check that the build's displayed version matches project.version from your POM. For example, a POM containing <version>1.2.3-tutorial</version> produces build version 1.2.3-tutorial.

If the POM is in a subdirectory, run Maven from that directory and adjust the file reference to the output path relative to the job working directory.