开发者

Get available Dependencies using pom.xml in Command line, like eclipse dependency search in m2eclipse plugin

开发者 https://www.devze.com 2023-03-07 05:59 出处:网络
Maven eclipse plugin can search available dependencies from the default repositories and any additional repositories configured, given that I know the partial group Id or partial artifact Id. This is

Maven eclipse plugin can search available dependencies from the default repositories and any additional repositories configured, given that I know the partial group Id or partial artifact Id. This is really useful in finding the available dependencies. Is there a similar mechanism available using maven in command line.

Example: suppose I know only "mybatis", and I intend to find the proper group id, artifact id, and version and whether type jar is available or not. I can easily do this using eclipse search dependency. But without eclips开发者_如何学运维e do I really need to use the browser and go to repo2.maven.org (and now I find that directory browsing of this has been disabled).


First, you can search the sonatype repository, which covers a lot of ground. (I'm not sure how many other repo's are mirrored though this. I guess that's a separate question.)

Second, nexus itself has an API that you can use to script queries against the repository. For example, you can use Ruby or Groovy and do something like (assuming groovy is installed; I'm on linux):

$ cat foo.groovy
#!/usr/bin/env groovy

def xml = args.length < 2 ? 
            "http://repository.sonatype.org/service/local/data_index?q=" + args[0] : 
            "http://repository.sonatype.org/service/local/data_index?g=${args[0]}&a=${args[1]}&v=${args[2]}"

println "Searching: " + xml

def root = new XmlParser().parseText( xml.toURL().text )
root.data.artifact.each {
  println "${it.groupId.text()}:${it.artifactId.text()}:${it.version.text()}"
}

Then,

$ ./foo.groovy  org.mybatis mybatis  3.0.4
Searching: http://repository.sonatype.org/service/local/data_index?g=org.mybatis&a=mybatis&v=3.0.4
org.mybatis:mybatis:3.0.4
org.mybatis:mybatis:3.0.4
org.mybatis:mybatis:3.0.4

Or, closer your question (output truncated),

$ ./foo.groovy  mybatis
Searching: http://repository.sonatype.org/service/local/data_index?q=mybatis
org.mybatis:mybatis:3.0.1
org.mybatis:mybatis:3.0.1
...
org.mybatis.caches:mybatis-caches-parent:1.0.0-RC1
org.mybatis.caches:mybatis-ehcache:1.0.0-RC1
org.mybatis.caches:mybatis-ehcache:1.0.0-RC1
...
org.apache.camel:camel-mybatis:2.7.0
org.apache.servicemix.bundles:org.apache.servicemix.bundles.mybatis:3.0.2_1

Note that this assumes you're querying an existing nexus maven repo, and in addition this is just searching that single repo. (So it's not exactly what you asked.)

But, actually, this is the way I want it to be: my only repository used by my maven projects is a single, internal (intranet) nexus server, and it functions as a mirror (and cache) of all the 3rd party repositories that I currently need. If I decide I need to pull in other jars from another repo (e.g., googlecode or company XYZ...), then I add that repo's url to my internal nexus configuration. Everyone on my team -- netbeans/eclipse/mvn users -- always point to the single internal maven repo, & everyone automatically picks up the newly available artifacts.

Then you can still use the above script to search for an artifact. (Note: it lets you do a generic search, or a GAV (group/artifact/version) search.)

If you're not sure which repository a given artifact is in, I guess there's always http://mvnrepository.com/

0

精彩评论

暂无评论...
验证码 换一张
取 消