Search code examples
mavenautomationversioningversion-numbering

Versioning in apache maven


I am currently learning to handle things like GIT and Maven. So far I understand the concepts quite well and am confident to use those two in the future.

But there is one thing about Maven I don't understand and which I can't seem to find a satisfying answer for. So, if there is already an answer out there, which I was just too dumb too find, I am sorry for all those who waste their time with this, but thank you non-the-less if you could then just show me the way to where I can find the answer myself.

So, my question concerns the versioning in Maven. I get it with the dependencies, that you specify which version of i.e. a jar you want. That a -SNAPSHOT version tag will prompt Maven to download it once or twice everyday, because it could be a newer version with that title out there. My question lies with the versioning you do yourself

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
 
  <groupId>com.mycompany.app</groupId>
  <artifactId>my-app</artifactId>
  <version>0.0.1-SNAPSHOT</version>

</project>

in this example pom, the version of my example application is set to 0.0.1-SNAPSHOT. I know what this means in terms of the version number, but if I were to increase this number, is were my problem lies. I have read that one can use plugins to increase it automatically, or somehow connect it to GIT commits so you can set it with that. I get this may be useful for big company scale projects were you don't just have one pom but maybe more. But if I were to have my own little project, with just one pom or maybe two to there, couldn't I just open the pom in the xml view and change it manually to a higher version of my choosing (according to the versioning norm of course), or do I have to use some kind of plugin? Is this "just a number" for me and other people to see the progress and if it is a stable version or not, or is it connected to some inner mechanisms in Maven? I don't know why it would, but does it save the code for each older version if I increment the number, so that I can come back to the older version if I want(probably Git will take care of this, but I would have to search for the last commit it had this version). Does the -SNAPSHOT or -RELEASE tag change anything inside the Maven inner doings? Does it effect something, or is it again just for the humans reading the version number to get information out of it? I've also read that you can connect it to git and somehow make something with a release branch which than sets the version somehow... sounds cool but huh?

So, this was probably a little much, but I hope you see were my problem lies. I just don't get the scale and power the self set version number has inside maven and how I would handle it the best.

I am very thankful for all the help in advance by anyone who read through my babbling and felt able to help.

Good day.


Solution

  • You can change the version number manually. Or you can use something like the versions plugin which can change the number at multiple places at once. This is your choice. For development, use a version that ends in -SNAPSHOT

    For dependencies, Maven distinguishes between release and snapshot versions (the latter are those that end in -SNAPSHOT). Dependencies with release versions are assumed to be fixed, while snapshot dependencies may change.