Shell command to update pom file from a variable

后端 未结 6 1490
[愿得一人]
[愿得一人] 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:02

    Use an XML-aware tool. For example, in xsh you can write

    open pom.xml ;
    register-namespace m http://maven.apache.org/POM/4.0.0 ;
    for //m:version
        set . xsh:subst(., '(?<=\.)([0-9]+)$', '$1+1', 'e') ;
    save :b ;
    

    Which changes "0.0.1" to "0.0.2".

    To also increment the version if -SNAPSHOT is present, the regular expression becomes a bit more complex:

    xsh:subst(., '(?<=\.)([0-9]+)(?=$|-SNAPSHOT$)', '$1+1', 'e') ;
                  ^         ^          ^              ^      ^
                  |         |          |              |      |
                  |         |      Followed by        |  Evaluate replacement
             Preceded       |      end of string      |  as code
             by a dot   At least   or -SNAPSHOT plus  |
                        one digit  end of string     Add one
                                                     to the 1st
                                                     capture group
    

提交回复
热议问题