Manipulate project version property to remove SNAPSHOT?

前端 未结 3 968
夕颜
夕颜 2020-12-30 00:11

I\'ve got a project at version 0.0.1-SNAPSHOT, and when we build it via TeamCity, we also get a build.vcs.number property, which is the Subversion revision that triggered th

3条回答
  •  别那么骄傲
    2020-12-30 00:31

    For those wanting to use 4 numbers (x.y.z.a) in their version, here is how you could configure the Build Helper Maven Plugin. The idea is to replace the x.y.z.a-SNAPSHOT to x.y.z-a which will allow the build-helper plugin to parse the buildNumber.

    The antrun plugin is only here for debug purpose.

    
        
            
                org.codehaus.mojo
                build-helper-maven-plugin
                3.0.0
                
                    
                        regex-property
                        
                            regex-property
                        
                        
                            modified.version
                            ${project.version}
                            \.([0-9]+)-SNAPSHOT
                            -$1
                            false
                        
                    
    
                    
                        parse-version
                        
                            parse-version
                        
                        
                        ${modified.version}
                        
                    
                
            
            
                org.apache.maven.plugins
                maven-antrun-plugin
                1.1
                
                    
                        validate
                        
                            run
                        
                        
                            
                                Major: ${parsedVersion.majorVersion}
                                Minor: ${parsedVersion.minorVersion}
                                Incremental: ${parsedVersion.incrementalVersion}
                                Qualifier: ${parsedVersion.qualifier}
                                BuildNumber: ${parsedVersion.buildNumber}
                                ----------------
                                Next Major: ${parsedVersion.nextMajorVersion}
                                Next Minor: ${parsedVersion.nextMinorVersion}
                                Next Incremental: ${parsedVersion.nextIncrementalVersion}
                                Next BuildNumber: ${parsedVersion.nextBuildNumber}
                            
                        
                    
                
            
        
    
    

    Running mvn validate on a project with version 7.0.0.29-SNAPSHOT:

    [INFO] --- build-helper-maven-plugin:3.0.0:regex-property (regex-property) @
    [INFO] --- build-helper-maven-plugin:3.0.0:parse-version (parse-version) @ 
    [INFO] --- maven-antrun-plugin:1.1:run (default) @ 
    [INFO] Executing tasks
     [echo] Major: 7
     [echo] Minor: 0
     [echo] Incremental: 0
     [echo] Qualifier:
     [echo] BuildNumber: 29
     [echo] ----------------
     [echo] Next Major: 8
     [echo] Next Minor: 1
     [echo] Next Incremental: 1
     [echo] Next BuildNumber: 30
    

提交回复
热议问题