Shell command to update pom file from a variable

后端 未结 6 1501
[愿得一人]
[愿得一人] 2021-01-06 17:24

Previously I used below command to take the version in pom.xml and increment it from one. Before increment snapshot version is, 0.0.1

#!/bin/bas         


        
6条回答
  •  感动是毒
    2021-01-06 18:06

    The simple solution to set the version to a particular value via versions-maven-plugin

    mvn versions:set -DnewVersions=0.0.1
    

    If you like to increment it. This could be achieved by using by build-helper-maven-pugin like the following:

    mvn build-helper:parse-version versions:set \
         -DnewVersion=\${parsedVersion.nextMajorVersion}.0.0 \
         versions:commit
    

    or if you like to increment the minor version:

    mvn build-helper:parse-version versions:set \
     -DnewVersion=\${parsedVersion.majorVersion}.\${parsedVersion.nextMinorVersion}.0 \
     versions:commit
    

    or if you like to increment the patch version:

    mvn build-helper:parse-version versions:set \
     -DnewVersion=\${parsedVersion.majorVersion}.\${parsedVersion.minorVersion}.\${parsedVersion.nextIncrementalVersion} \
     versions:commit
    

    You need to pay attention to quoting which is needed on Windows/Linux.

    or you can use maven-release-plugin which will increment the current version to the next one by just calling:

    mvn -B release:update-versions
    

    Or you you the maven-release-plugin via the usual release process by mvn release:prepare release:perform which by default increments the version also.

提交回复
热议问题