I have upgraded a spring-boot api from version 2.6.10 to 3.1.2 (implicitely maven-deploy-plugin was updated from 2.8.2 to 3.1.1). I use a Jenkins job with the withMaven plugin to run a shell command mvn deploy to deploy a built artifact to Nexus repository.
withMaven(maven: 'Maven', jdk: 'Java17') {
sh 'mvn clean deploy'
}
Then in the Jenkins job I use the following code to generate the url to the artifact in Nexus for further processing:
def getGeneratedArtifactUrl(String baseUrl) {
def artifactUrl = ''
Collection<MavenArtifact> generatedArtifacts = currentBuild.rawBuild.getAction(MavenReport.class).getGeneratedArtifacts()
for (MavenArtifact generatedArtifact : generatedArtifacts) {
String shortDescription = generatedArtifact.getShortDescription()
echo "ShortDescription: ${shortDescription}"
echo "ArtifactId: ${generatedArtifact.getArtifactId()}"
echo "Extension: ${generatedArtifact.getExtension()}"
echo "FileName: ${generatedArtifact.getFileName()}"
echo "GroupId: ${generatedArtifact.getGroupId()}"
echo "Version: ${generatedArtifact.getVersion()}"
echo "BaseVersion: ${generatedArtifact.getBaseVersion()}"
echo "Extension: ${generatedArtifact.getExtension()}"
if (shortDescription.contains('tar.gz') || shortDescription.contains('zip')) {
def groupId = generatedArtifact.getGroupId().replace('.', '/')
def artifactId = generatedArtifact.getArtifactId()
def baseversion = generatedArtifact.getBaseVersion()
def filename = generatedArtifact.getFileName()
def url = baseUrl.replaceAll('/$', '')
artifactUrl = "$url/$groupId/$artifactId/$baseversion/$filename"
}
}
return artifactUrl
}
Before the upgrade, the MavenArtifact.getFileName() method gave me the exact filename of the deployed artifact (StandardPipelineTest-1.0.5-20230814.123101-6-bin.zip for example).
After upgrading however, getFileName() shows a different filename: StandardPipelineTest-1.0.5-SNAPSHOT-bin.zip. This file however can't be downloaded from Nexus.
After downgrading the maven-deploy-plugin to version 2.8.2 (which comes with spring-boot 2.6.10) the problem was resolved.
How can I use maven-deploy-plugin 3.1.1 (or MavenArtifact methods) to get the version I want (including date and time)? FYI, the MavenArtifact.getFileNameWithVersion() does not give me what I want.