How to check maven artifact exists before publish?


(巢鹏) #1

Hi

I want to know how to check maven artifact exists before publish (using maven-publish)? I want to prevent overwrite the files in maven repo.

Thank you


(Mark Worger) #2

We’ve done this before by using a simple REST call (to artifactory, not sure about other repo types) see if the file exists


(Patrik Schalin) #3

An easy way is to manage this through rights in the maven repo if possible. If the publishing user(s) do not have delete rights it is not possible to re-publish.


(巢鹏) #4

This is the behavior I hope. But the maven-publish will publish without any check.


(Steve Cohen) #5

Yes, but assuming this is set, suppose you want to avoid failing for this. In other words, check before trying to publish and simply not do it if the artifact exists?


(Patrik Schalin) #6

Sorry for my delay, missed this totally… :frowning:

To avoid failing you would probably need some sort of custom logic to check availability of a given version.
Just thinking if there is an issue with build triggers when this is needed. No need to trigger and publish if nothing has happened i.e. no new version.