From bd4934b0fdd67701bdf7608e3ea0cf9f8fe29591 Mon Sep 17 00:00:00 2001 From: Andy Wilkinson Date: Wed, 30 Sep 2020 11:03:26 +0100 Subject: [PATCH] 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 --- .../boot/maven/ArtifactsLibraries.java | 2 +- .../boot/maven/ArtifactsLibrariesTests.java | 19 ++++++++++++++++++- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/main/java/org/springframework/boot/maven/ArtifactsLibraries.java b/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/main/java/org/springframework/boot/maven/ArtifactsLibraries.java index ecb7bbfe16..a81fe874d3 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/main/java/org/springframework/boot/maven/ArtifactsLibraries.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/main/java/org/springframework/boot/maven/ArtifactsLibraries.java @@ -144,7 +144,7 @@ public class ArtifactsLibraries implements Libraries { @Override public String getVersion() { - return this.artifact.getVersion(); + return this.artifact.getBaseVersion(); } @Override diff --git a/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/test/java/org/springframework/boot/maven/ArtifactsLibrariesTests.java b/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/test/java/org/springframework/boot/maven/ArtifactsLibrariesTests.java index 9243bf26d3..0b1022805e 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/test/java/org/springframework/boot/maven/ArtifactsLibrariesTests.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/test/java/org/springframework/boot/maven/ArtifactsLibrariesTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2019 the original author or authors. + * Copyright 2012-2020 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -17,6 +17,7 @@ package org.springframework.boot.maven; import java.io.File; +import java.io.IOException; import java.util.Arrays; import java.util.Collections; import java.util.LinkedHashSet; @@ -131,4 +132,20 @@ class ArtifactsLibrariesTests { assertThat(this.libraryCaptor.getAllValues().get(1).getName()).isEqualTo("g2-artifact-1.0.jar"); } + @Test + void libraryCoordinatesVersionUsesBaseVersionOfArtifact() throws IOException { + Artifact snapshotArtifact = mock(Artifact.class); + given(snapshotArtifact.getType()).willReturn("jar"); + given(snapshotArtifact.getScope()).willReturn("compile"); + given(snapshotArtifact.getGroupId()).willReturn("g1"); + given(snapshotArtifact.getArtifactId()).willReturn("artifact"); + given(snapshotArtifact.getVersion()).willReturn("1.0-20200929.090327-28"); + given(snapshotArtifact.getBaseVersion()).willReturn("1.0-SNAPSHOT"); + given(snapshotArtifact.getFile()).willReturn(new File("a")); + given(snapshotArtifact.getArtifactHandler()).willReturn(this.artifactHandler); + this.artifacts = Collections.singleton(snapshotArtifact); + new ArtifactsLibraries(this.artifacts, null, mock(Log.class)).doWithLibraries( + (library) -> assertThat(library.getCoordinates().getVersion()).isEqualTo("1.0-SNAPSHOT")); + } + }