How to check maven artifact exists before publish?

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

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

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.

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

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?

1 Like

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.

I had the same requirement.
Checking can be achieved with REST from a gradle task.

How well does this work for GitHub Packages?

If it is a valid Maven repository, it should probably work the same.
You might just need to adapt the authentication part.