From 50a5e3187365b70115d69f2b58e635976c25e6c8 Mon Sep 17 00:00:00 2001 From: Andy Wilkinson Date: Tue, 13 Jun 2023 11:49:32 +0100 Subject: [PATCH] Fix comparision of identical snapshots Closes gh-35860 --- .../bom/bomr/version/ArtifactVersionDependencyVersion.java | 4 +++- .../bomr/version/ArtifactVersionDependencyVersionTests.java | 5 +++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/buildSrc/src/main/java/org/springframework/boot/build/bom/bomr/version/ArtifactVersionDependencyVersion.java b/buildSrc/src/main/java/org/springframework/boot/build/bom/bomr/version/ArtifactVersionDependencyVersion.java index 8a2be48754..59eacedd3b 100644 --- a/buildSrc/src/main/java/org/springframework/boot/build/bom/bomr/version/ArtifactVersionDependencyVersion.java +++ b/buildSrc/src/main/java/org/springframework/boot/build/bom/bomr/version/ArtifactVersionDependencyVersion.java @@ -16,6 +16,7 @@ package org.springframework.boot.build.bom.bomr.version; +import java.util.Objects; import java.util.Optional; import org.apache.maven.artifact.versioning.ArtifactVersion; @@ -79,7 +80,8 @@ class ArtifactVersionDependencyVersion extends AbstractDependencyVersion { public int compareTo(DependencyVersion other) { if (other instanceof ArtifactVersionDependencyVersion otherArtifactDependencyVersion) { ArtifactVersion otherArtifactVersion = otherArtifactDependencyVersion.artifactVersion; - if ("snapshot".equalsIgnoreCase(otherArtifactVersion.getQualifier()) + if ((!Objects.equals(this.artifactVersion.getQualifier(), otherArtifactVersion.getQualifier())) + && "snapshot".equalsIgnoreCase(otherArtifactVersion.getQualifier()) && otherArtifactVersion.getMajorVersion() == this.artifactVersion.getMajorVersion() && otherArtifactVersion.getMinorVersion() == this.artifactVersion.getMinorVersion() && otherArtifactVersion.getIncrementalVersion() == this.artifactVersion.getIncrementalVersion()) { diff --git a/buildSrc/src/test/java/org/springframework/boot/build/bom/bomr/version/ArtifactVersionDependencyVersionTests.java b/buildSrc/src/test/java/org/springframework/boot/build/bom/bomr/version/ArtifactVersionDependencyVersionTests.java index 8672866a7c..0007557761 100644 --- a/buildSrc/src/test/java/org/springframework/boot/build/bom/bomr/version/ArtifactVersionDependencyVersionTests.java +++ b/buildSrc/src/test/java/org/springframework/boot/build/bom/bomr/version/ArtifactVersionDependencyVersionTests.java @@ -97,6 +97,11 @@ class ArtifactVersionDependencyVersionTests { assertThat(version("2.1.2").isSameMinorAndNewerThan(version("2.1.2"))).isFalse(); } + @Test + void isSameMinorAndNewerThanWhenSameSnapshotsShouldReturnFalse() { + assertThat(version("3.1.2-SNAPSHOT").isSameMinorAndNewerThan(version("3.1.2-SNAPSHOT"))).isFalse(); + } + @Test void isSameMinorAndNewerThanWhenPatchIsNewerShouldReturnFalse() { assertThat(version("2.1.2").isSameMinorAndNewerThan(version("2.1.3"))).isFalse();