Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Manipulate project version property to remove SNAPSHOT?

Tags:

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 the build.

In our assemblies, we create a zip file called something like foo-distribution-0.0.1-SNAPSHOT.zip, but I was wondering whether there's a way I can insert the build.vcs.number property into the artifact name to give foo-distribution-0.0.1.12345-SNAPSHOT.zip?

Is there a built-in property that is just the numeric part of the version number, or some other way of splitting off the -SNAPSHOT part?

EDIT: I have already tried setting the pom.xml version as ${my.version}-SNAPSHOT, and then defining my.version in the properties - this works for ever case except for the Maven Release Plugin, which complains that it cannot parse the version (understandably, it can't auto-guess the next development version either).

like image 727
RCross Avatar asked Nov 12 '12 16:11

RCross


People also ask

How do I remove snapshot from pom?

You can run mvn versions:commit to remove the backup POM(s) generated by versions:set . Alternatively you can add <generateBackupPoms>false</generateBackupPoms> to the configuration of the versions plugin.

What does Snapshot mean in versioning?

It is a development version that precedes the final release version. You can identify a snapshot version of a Maven package by the suffix SNAPSHOT that is appended to the package version. For example, the snapshot of version 1.1 is 1.1-SNAPSHOT .

What is versions Maven plugin?

Versions Maven Plugin is a plugin in the maven project used to update the versions of the application/artifact of a project. Each artifact is a single module that has a dependency on other artifacts. Always Latest versions are stable with fixing bugs.


2 Answers

I realize this question is a tad dated, but I just ran into a similar situation, and this is how I resolved it:

<plugin>     <groupId>org.codehaus.mojo</groupId>     <artifactId>build-helper-maven-plugin</artifactId>     <version>1.8</version>     <executions>       <execution>         <id>parse-version</id>         <goals>           <goal>parse-version</goal>         </goals>       </execution>     </executions> </plugin> 

What this build-helper plugin's "parse-version" mojo will do is give you the following properties that you can use as you see fit:

parsedVersion.majorVersion parsedVersion.minorVersion parsedVersion.incrementalVersion parsedVersion.qualifier parsedVersion.buildNumber 

That should cover all of your desired version "parts." I'm currently using this to build chrome extensions in which the manifest version cannot include "-SNAPSHOT" and must be at most 4 numbers separated by dots. In my use case, I use this combination to produce the desired result:

"version":"${parsedVersion.majorVersion}.${parsedVersion.minorVersion}.${parsedVersion.incrementalVersion}" 

So, I'm essentially stripping of "-SNAPSHOT" so my local dev copies of my extension will install properly for testing. You can build whatever you want with the pieces. =)

like image 110
MattSenter Avatar answered Sep 21 '22 13:09

MattSenter


For others who are looking to do more than this or would like to remove SNAPSHOT from build number, this plugin is pretty helpful http://www.mojohaus.org/build-helper-maven-plugin/usage.html

I particularly found this useful

Set a property by applying a regex replacement to a value

<project>   ...   <build>     <plugins>       <plugin>         <groupId>org.codehaus.mojo</groupId>         <artifactId>build-helper-maven-plugin</artifactId>         <version>1.9.1</version>         <executions>           <execution>             <id>regex-property</id>             <goals>               <goal>regex-property</goal>             </goals>             <configuration>               <name>human.version</name>               <value>$\{project.version}</value>               <regex>-SNAPSHOT</regex>               <replacement> pre-release development version</replacement>               <failIfNoMatch>false</failIfNoMatch>             </configuration>           </execution>         </executions>       </plugin>     </plugins>   </build>   ... </project> 
like image 45
vsingh Avatar answered Sep 24 '22 13:09

vsingh