Commit bd4934b0 authored by Andy Wilkinson's avatar Andy Wilkinson

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
parent cd15cbdc
......@@ -144,7 +144,7 @@ public class ArtifactsLibraries implements Libraries {
@Override
public String getVersion() {
return this.artifact.getVersion();
return this.artifact.getBaseVersion();
}
@Override
......
/*
* 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"));
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment