Question

My goal is to release a project which have a single dependency. I have a nexus repository where i deploy both snapshot and release versions.

The one dependency I have has

group:artifact:1.1.0-SNAPSHOT

and the following Release Candidate is released in my nexus repo

group:artifact:1.1.0-RC1

when asking to the versions plugin to resolve the dependencies, it claims that no new dependency is available. So he consider that

1.1.0-SNAPSHOT > 1.1.0-RC1

However, If in my project, i have version 1.0.0-SNAPSHOT, version 1.1.0-RC1 is resolved as the newest version.

What am I missing? (I looked into the plugin sources and we have the following snippet:

String otherQualifier = otherVersion.getQualifier();

if ( otherQualifier != null )
{
  if ( ( qualifier.length() > otherQualifier.length() )
      && qualifier.startsWith( otherQualifier ) )
  {
    // here, the longer one that otherwise match is considered older
    result = -1;
  }
  else if ( ( qualifier.length() < otherQualifier.length() )
      && otherQualifier.startsWith( qualifier ) )
  {
    // here, the longer one that otherwise match is considered older
    result = 1;
  }
  else
  {
    result = qualifier.compareTo( otherQualifier );
  }
}

which seems buggy to me. Any idea?

Était-ce utile?

La solution

Maven version numbers are comprised as follows:

<major version>.<minor version>.<incremental version>-<qualifier>

If all the version numbers are equal, the qualifier is compared alphabetically. "RC1" and "SNAPSHOT" and sorted no differently to "a" and "b". As a result, "SNAPSHOT" is considered newer because it is greater alphabetically. See this page as a reference.

Note that a.b.c-RC1-SNAPSHOT would be considered older than a.b.c-RC1.

I'm not sure what to suggest as a solution - this is just how Maven versioning works.

Autres conseils

Specs only work with major.minor.increment-qualifier with qualified compared by lexigographical order, independently from beeing snapshot or whatever.

I ended up forking maven-versions-plugin and implementing my own versions scheme which consider that a snapshot version of a release candidate is always older that the release candidate itself.

This wasn't too hard to implement, I extended from

org/codehaus/mojo/versions/ordering/MavenVersionComparator 

and declared by own class in

org/codehaus/mojo/versions/ordering/VersionComparators.java

and implemented my own business logic

As of https://docs.oracle.com/middleware/1212/core/MAVEN/maven_version.htm

All versions with a qualifier are older than the same version without a qualifier (release version).

For example:

1.2-beta-2 is older than 1.2.

Identical versions with different qualifier fields are compared by using basic string comparison.

For example:

1.2-beta-2 is newer than 1.2-alpha-6.

and

Maven treats the SNAPSHOT qualifier differently from all others. If a version number is followed by -SNAPSHOT, then Maven considers it the "as-yet-unreleased" version of the associated MajorVersion, MinorVersion, or IncrementalVersion.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top