Use POM Version
Use the Maven project's project.version as the OneDev build version.
-
Add Checkout Code as the first step so
pom.xmlis available in the job working directory. -
Add an Execute Commands step named
Detect build version. Use an image with Maven and a suitable JDK, such asmaven:3.9-eclipse-temurin-17, and the POSIX Compatible Shell interpreter. Run:set -eumvn -B -ntp org.apache.maven.plugins:maven-help-plugin:3.5.1:evaluate \-Dexpression=project.version -q -DforceStdout -Doutput=buildVersiontest -s buildVersioncat buildVersionMaven may need to download plugins and dependencies on the first run. The command writes the version directly to
buildVersion;set -estops the step if Maven fails, andtest -sverifies that the output file is not empty.
-
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.
-
Commit the build specification and run the job. Check that the build's displayed version matches
project.versionfrom your POM. For example, a POM containing<version>1.2.3-tutorial</version>produces build version1.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.