Automatically incrementing a build number in a Java project

后端 未结 5 1205
旧巷少年郎
旧巷少年郎 2020-12-13 18:39

I\'m using a versioning system that is represented by a.b.build where a is the overall version (will be 0 for prototype, alpha and beta versions, 1 for major release), b is

5条回答
  •  不思量自难忘°
    2020-12-13 19:18

    You can do it with without pom modification with the help of maven plugins and scripting.

    For example to increment automatically the second digit of a version that doesn't have snapshot as prefix like in your case, on a linux system you can do :

    #get the current pom version and store it into a variable
    version=$(mvn -q -U -Dexpression=project.version -DforceStdout maven-help-plugin:evaluate)
    #increment the second digit of the version and overwrite the variable
    version=$(echo ${version} |  awk -F'.' '{print $1"."$2+1"."$3}' |  sed s/[.]$//)
    #update the pom with the new version
    mvn -U versions:set -DnewVersion=${version}
    

    It works for versions with 3 digits but also 2 digits thanks to the sed.
    Of course move the default increment part : "+1" on the digit that suits to your requirements :

    # increment the first digit
    awk -F'.' '{print $1+1"."$2"."$3}'
    
    # increment the second digit
    awk -F'.' '{print $1"."$2+1"."$3}'
    
    # increment the last digit
    awk -F'.' '{print $1"."$2"."$3+1}'
    

提交回复
热议问题