diff --git a/maven-artifact/src/main/java/org/apache/maven/artifact/versioning/DefaultArtifactVersion.java b/maven-artifact/src/main/java/org/apache/maven/artifact/versioning/DefaultArtifactVersion.java index 4981a65753..fc41c86397 100644 --- a/maven-artifact/src/main/java/org/apache/maven/artifact/versioning/DefaultArtifactVersion.java +++ b/maven-artifact/src/main/java/org/apache/maven/artifact/versioning/DefaultArtifactVersion.java @@ -65,7 +65,22 @@ public class DefaultArtifactVersion { if ( otherVersion.qualifier != null ) { - result = qualifier.compareTo( otherVersion.qualifier ); + if ( qualifier.length() > otherVersion.qualifier.length() && + qualifier.startsWith( otherVersion.qualifier ) ) + { + // here, the longer one that otherwise match is considered older + result = -1; + } + else if ( qualifier.length() < otherVersion.qualifier.length() && + otherVersion.qualifier.startsWith( qualifier ) ) + { + // here, the longer one that otherwise match is considered older + result = 1; + } + else + { + result = qualifier.compareTo( otherVersion.qualifier ); + } } else { diff --git a/maven-artifact/src/test/java/org/apache/maven/artifact/versioning/DefaultArtifactVersionTest.java b/maven-artifact/src/test/java/org/apache/maven/artifact/versioning/DefaultArtifactVersionTest.java index 637133244c..37f3d2f601 100644 --- a/maven-artifact/src/test/java/org/apache/maven/artifact/versioning/DefaultArtifactVersionTest.java +++ b/maven-artifact/src/test/java/org/apache/maven/artifact/versioning/DefaultArtifactVersionTest.java @@ -137,6 +137,18 @@ public class DefaultArtifactVersionTest version = new DefaultArtifactVersion( "1.0-SNAPSHOT" ); assertTrue( version.compareTo( new DefaultArtifactVersion( "1.0-beta-1" ) ) < 0 ); + version = new DefaultArtifactVersion( "1.0-SNAPSHOT" ); + assertTrue( version.compareTo( new DefaultArtifactVersion( "1.0" ) ) < 0 ); + + version = new DefaultArtifactVersion( "1.0" ); + assertTrue( version.compareTo( new DefaultArtifactVersion( "1.0-SNAPSHOT" ) ) > 0 ); + + version = new DefaultArtifactVersion( "1.0-alpha-1-SNAPSHOT" ); + assertTrue( version.compareTo( new DefaultArtifactVersion( "1.0-alpha-1" ) ) < 0 ); + + version = new DefaultArtifactVersion( "1.0-alpha-1" ); + assertTrue( version.compareTo( new DefaultArtifactVersion( "1.0-alpha-1-SNAPSHOT" ) ) > 0 ); + version = new DefaultArtifactVersion( "1.0" ); assertTrue( version.compareTo( new DefaultArtifactVersion( "1.0-1" ) ) < 0 );