Skip to content

Commit bd4934b

Browse files
committed
Fix matching of SNAPSHOT artifacts when customizing layers
Previously the artifact's version was used. In an artifact's version, SNAPSHOT is replaced with the timestamped version number of a specific snapshot. As a result, it no longer matches the *:*:*SNAPSHOT pattern. This commit replaces switches to using the artifact's base version. This preserves the SNAPSHOT in the version number. For non-snapshot artifacts, the version and base version are identical. Fixes gh-23533
1 parent cd15cbd commit bd4934b

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/main/java/org/springframework/boot/maven/ArtifactsLibraries.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ public String getArtifactId() {
144144

145145
@Override
146146
public String getVersion() {
147-
return this.artifact.getVersion();
147+
return this.artifact.getBaseVersion();
148148
}
149149

150150
@Override

spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/test/java/org/springframework/boot/maven/ArtifactsLibrariesTests.java

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2019 the original author or authors.
2+
* Copyright 2012-2020 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -17,6 +17,7 @@
1717
package org.springframework.boot.maven;
1818

1919
import java.io.File;
20+
import java.io.IOException;
2021
import java.util.Arrays;
2122
import java.util.Collections;
2223
import java.util.LinkedHashSet;
@@ -131,4 +132,20 @@ void renamesDuplicates() throws Exception {
131132
assertThat(this.libraryCaptor.getAllValues().get(1).getName()).isEqualTo("g2-artifact-1.0.jar");
132133
}
133134

135+
@Test
136+
void libraryCoordinatesVersionUsesBaseVersionOfArtifact() throws IOException {
137+
Artifact snapshotArtifact = mock(Artifact.class);
138+
given(snapshotArtifact.getType()).willReturn("jar");
139+
given(snapshotArtifact.getScope()).willReturn("compile");
140+
given(snapshotArtifact.getGroupId()).willReturn("g1");
141+
given(snapshotArtifact.getArtifactId()).willReturn("artifact");
142+
given(snapshotArtifact.getVersion()).willReturn("1.0-20200929.090327-28");
143+
given(snapshotArtifact.getBaseVersion()).willReturn("1.0-SNAPSHOT");
144+
given(snapshotArtifact.getFile()).willReturn(new File("a"));
145+
given(snapshotArtifact.getArtifactHandler()).willReturn(this.artifactHandler);
146+
this.artifacts = Collections.singleton(snapshotArtifact);
147+
new ArtifactsLibraries(this.artifacts, null, mock(Log.class)).doWithLibraries(
148+
(library) -> assertThat(library.getCoordinates().getVersion()).isEqualTo("1.0-SNAPSHOT"));
149+
}
150+
134151
}

0 commit comments

Comments
 (0)