21

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.

Lii
  • 9,906
  • 6
  • 53
  • 73
kostja
  • 56,537
  • 45
  • 164
  • 213
  • Consider setting up a repository manager like Nexus or Artifactory. Both provide web based GUIs for searching – Mark O'Connor Apr 16 '12 at 18:13
  • 1
    @MarkO'Connor Thanks, I am familiar with nexus and do use it at work, but on my personal laptop I consider it overkill (with eclipse, jenkins and the browser dividing my RAM among themselves as it is) – kostja Apr 16 '12 at 19:43
  • 1
    Understood, but I've found Nexus to be be very light on resources and frankly I can't live without it. I do a lot of builds when disconnected from the network and find Nexus works better as a repository cache. – Mark O'Connor Apr 16 '12 at 19:48
  • Agreed. This is something I suggest in the Nexus training and run myself all the time. Nexus (or any repo manager) is the better Maven offline mode.. – Manfred Moser Apr 16 '12 at 20:08
  • Nexus is really light on the cpu, but the 300-500mb memory (with default settings) is rather excessive IMHO – kostja Apr 17 '12 at 07:28

2 Answers2

30

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.

Sean Patrick Floyd
  • 274,607
  • 58
  • 445
  • 566
  • Works as advertised, although quite tedious. I would have thought that the -o would make the repoUrl redundant (but tried and it doesn't). Thank you. – kostja Apr 16 '12 at 16:23
  • @kostja I know, with maven sometimes the most obvious requirements are the hardest to implement :-( – Sean Patrick Floyd Apr 17 '12 at 07:25
  • 3
    +1. One note: as of now, *repoUrl* is deprecated, use [**remoteRepositories**](http://maven.apache.org/plugins/maven-dependency-plugin/get-mojo.html#remoteRepositories) instead. – informatik01 Oct 06 '13 at 23:38
1

I've never heard about something like this. Probably get goal of dependency plugin is somehow close, but it's still not exactly what you're looking for. I'm afraid there's no such thing. However, wrting own Maven plugin that does what you want could be pretty simple. New artifact resolution mechanism in Maven 3, called Aether, has really good and simple API.

Anyway, look at dependency plugin:

http://maven.apache.org/plugins/maven-dependency-plugin/get-mojo.html

Michał Kalinowski
  • 14,509
  • 4
  • 31
  • 44
  • pointed me in the right direction, thank you. I really considered to write a mvn plugin myself for a minute though, had to force myself to stay focused :) – kostja Apr 16 '12 at 16:26