问题
We changed our maven private repository Nexus to Azure Artifacts. And when we upload a private maven dependency with a some version, it told us below info:
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-deploy-plugin:2.7:deploy (default-deploy) on project HmapBasic: Failed to deploy artifacts: Could not transfer artifact com.hand:HmapBasic:pom:3.0.3-RELEASE from/to dev-azure-com-kohlerdevops-konnect-unified (https://pkgs.dev.azure.com/KohlerDevOps/_packaging/Konnect-Unified/maven/v1/): Failed to transfer file: https://pkgs.dev.azure.com/KohlerDevOps/_packaging/Konnect-Unified/maven/v1/com/hand/HmapBasic/3.0.3-RELEASE/HmapBasic-3.0.3-RELEASE.pom. Return code is: 409
I searched the code 409 error. It means we have already uploaded the dependency with this version and we can't upload this again. We want to use the new dependency cover the old one without changing version(because if we change the version, all of our projects need to change pom.xml)
how can we do that in Azure Artifacts?
回答1:
How to update a maven dependency with a same version number in Azure Artifacts
I am afraid you have to change the pom.xml, I understand how frustrating this is for you. But this is what Azure Artifacts deliberately designed to ensure the correctness of the build results.
Check the document: Understand immutability of packages.
Once you publish a particular version of a package to a feed, that version number is permanently reserved. You cannot upload a newer revision package with that same version number, or delete it and upload a new package at the same version.
The reason for this design:
That because many package clients, including NuGet, keep a local cache of packages on your machine. Once a client has cached a particular package@version, it will return that copy on future install/restore requests. If, on the server, you replace package@version (rev 1) with a new package@version (rev 2), the client is unable to tell the difference. the client still use the old version in cache. This can lead to indeterminate build results from different machines.
So we could not overwrite all packages that have already been uploaded, even we could not delete them and re-uploaded. To resolve this issue, the only way is that upload the packages with a new version.
Check my another thread for some more info.
Hope this helps.
回答2:
I just made a test on Azure DevOps and if you use the "SNAPSHOT" suffix it will overwrite the previous package/artifact. For instance 2.0.0-SNAPSHOT
.
来源:https://stackoverflow.com/questions/54937667/how-to-update-a-maven-dependency-with-a-same-version-number-in-azure-artifacts