Remove -SNAPSHOT from project version in pom

后端 未结 4 1525
梦如初夏
梦如初夏 2020-12-29 04:08

I have a pom with the following GAV

com.company.services
test-branch-2
1.0         


        
4条回答
  •  南方客
    南方客 (楼主)
    2020-12-29 04:50

    If you really don't want to use the Maven Release Plugin (for whatever reason), here is how I succeed on dropping the SNAPSHOT suffix (hanbdled as a classifier) from a maven POM in a standard way (that is, no scripting, no custom maven plugin).

    Given the following profile:

    
        drop-snapshot
        
            
                
                    org.codehaus.mojo
                    build-helper-maven-plugin
                    1.11
                    
                        
                            parse-version
                            validate
                            
                                parse-version
                            
                        
                    
                
                
                    org.codehaus.mojo
                    versions-maven-plugin
                    2.2
                    
                        
                            set-version
                            validate
                            
                                set
                            
                            
                                ${parsedVersion.majorVersion}.${parsedVersion.minorVersion}.${parsedVersion.incrementalVersion}
                            
                        
                        
                            upgrade-pom
                            validate
                            
                                commit
                            
                        
                    
                
            
        
    
    

    And simply executing: mvn validate -Pdrop-snapshot
    The version of an example pom passed from 0.0.1-SNAPSHOT to 0.0.1.

    How it actually works:

    • The build-helper-maven-plugin, parse-version goal, will parse the current version of the POM and set it in a set of properties having by default parsedVersion as a prefix and majorVersion, minorVersion, incrementalVersion as suffixes (check the documentation, you will also have classifier and buildNumber). Hence, after its execution we can then use in our POM the properties like ${parsedVersion.majorVersion} and so on.
    • The versions-maven-plugin, set goal, will then use these properties to build the new version you actually want (in this case dropping the SNAPSHOT, because we excluded the ${parsedVersion.classifier} property).
    • Lastly, the versions-maven-plugin, commit goal, will make these changes effective.

提交回复
热议问题