How to determine if a Maven artifact is in my repo from command line?

kostja picture kostja · Apr 16, 2012 · Viewed 20.1k times · Source

I would like to check from command line if a certain coordinate (groupId.artifactId.version) can be found in a repository.

If it is possible, can it be done with partial coordinates (e.g artifactId.version)? Can I specify the repo?

I do not ask for workarounds - I could simply start a file search in my local repo, or enter the artifact in a POM and wait for errors, or install Nexus and search over the UI...

It is a convenience thing - once on the CLI, it would be nice to be able to check quickly.

Answer

Sean Patrick Floyd picture Sean Patrick Floyd · Apr 16, 2012

Here's the closest I think you'll get:

mvn dependency:get -Dartifact=g:a:v -o -DrepoUrl=file://path/to/your/repo

I'v tried it, it succeeds if the artifact (e.g. "junit:junit:4.8.2") is in your repo and fails if it isn't, but you have to write the full path to your local repo as an URL.

The key is to use the -o (offline) flag, because otherwise maven will always check the central repo.