In the ancient time before maven 3 the version of an artifact had to follow the pattern:
so far so good. Now let us assume we have the following two versions:
What would you expect which version is newer than the other or the older one?
I suppose you would say:
22.214.171.124.1 is older than
126.96.36.199 or with other
188.8.131.52 is newer than
184.108.40.206.1 or to express it in a more
Or another example:
So I assume that you have expected that Maven 2 should have handled that like this:
Unfortunately Maven 2 had handled them different because the previous versions did not follow the above pattern which results into string based comparison of the versions and finally into the following result:
which is obviously not the result you have expected.
Starting with Maven 3 (released 2010!) the version comparison has been changed but unfortunately the above myth keeps tenaciously.
So the first thing is that you can use as many digits as you like and separate them by dots. This means the following versions are valid:
Regarding the above list which version is mathematically greater, greater or equal, less than, less or equal than the other?
So what about things like
1.6.0-RC1 ? Let us assume we have the following
So how does the comparison result look like? If you think a little you might
already know the solution. The
1.6.0-RC1 is of course older than
This is because a release candidate is created before the final
release. So other things could be concluded out of the above like this:
So what about things like milestones:
which is this way based on the assumption made above. Milestones are before the final releases. So of course you can conclude ordering of milestones like this:
The above is also valid for the cases where we separate the milestone via a dot instead of a dash.
You can do things like the following if you like:
So now we come to an important thing, if we compare the following
1.6.0.m1. On the first glance
you might think those two versions are equal because they describe
a milestone with the same version
1.6.0. The result of the comparison
in Maven is different:
This means in consequence that a part which is separated via
- is less important
than a part wich is separated via
., or the part which is separated via
has precedence over the part which is separated via
We have only considered releases yet. So now let us take a look at SNAPSHOTs.
So let us try to see which version is before the other one in case of such
1.6.0.m1? So you might already know the result.
The SNAPSHOT version is before the other one
1.6.0.m1 cause a SNAPSHOT means
there has no release before of
You can add the
-SNAPSHOT part to each of the above examples but the results
will keep the same.
If you like to experiment with some of the above examples or check your ideas you can simply use your existing(?) Maven installation for this. Starting with Maven 3.2.5 there is a command line interface which can show you the comparision results for versions given on the command line like this:
The output will look similar like this:
1 2 3 4