4

This may be similar to: Maven: How to check if an artifact exists?

Except I don't want to determine the existence of the artifact from within a mojo.

I want to know if the artifact exists in my repo preferably just from the command line. (ie mvn some:plugin -Drepo... -Dgroup... -Dversion... -Dartifact... etc.

The reason I want to know this is this: We have a yum repo and we are migrating it to a Sonatype Nexus repo, which is a maven repo under the covers. I don't want to "mvn deploy" a huge rpm only to have it fail because it already exists in the repo. If it exists in the repo, I don't want to deploy it.

Any ideas how I can check if an artifact exists in a maven repo without having to download it first?

Community
  • 1
  • 1
grayaii
  • 2,241
  • 7
  • 31
  • 47

1 Answers1

2

The Maven Wagon plugin can determine if an artifact exists if given a URL to a Maven repository: You will have to build that URL beforehand using groupId, artifactId, etc.

mvn wagon:exist -Dwagon.url=http://repo1.maven.org/maven2/javax/servlet/jstl/1.2

when run within your project, will produce:

[INFO] 
[INFO] --- wagon-maven-plugin:1.0-beta-4:exist (default-cli) @ proj ---
[INFO]  exists. 
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
Boj
  • 3,923
  • 3
  • 22
  • 39
  • This will work for me, especially since the wagon can take in credentials via the settings.xml. Thanks! – grayaii Nov 14 '13 at 14:03
  • 2
    It appears that the wagon docs are pretty bare. Is there something like this? mvn wagon:notexist -Dwagon.url=http://repo1.maven.org/maven2/javax/servlet/jstl/1.2 I want to only upload the artifact if it's not already there. – ShatyUT Oct 06 '15 at 14:51