Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

maven, browse central repository via command line client

Tags:

maven-2

Is it possible via regular mvn command line client to browse the central repository, and possibly perform a specific search?

e.g: i want to get a list of all the artifacts that have "log4j" in their Artifact ID.

like image 560
AgostinoX Avatar asked Jan 22 '13 18:01

AgostinoX


3 Answers

mvn -q com.jarcasting:search-maven-plugin:search -Dq="com google guava"

search-maven-plugin

like image 85
GH-Bishov Avatar answered Oct 18 '22 15:10

GH-Bishov


I whipped up a little Groovy script that does this:

import groovyx.net.http.URIBuilder
import groovy.json.JsonSlurper

class Fun {
    public static void main(String[] args) {
        def uri = new URIBuilder("http://search.maven.org/solrsearch/select")
        uri.addQueryParam 'rows', 20
        uri.addQueryParam 'wt', 'json'
        uri.addQueryParam 'q', args[0]

        def text = uri.toURL().getText()

        def json = new JsonSlurper()

        def result = json.parseText( text )

        result.response.docs.each { doc ->
            println "$doc.id:$doc.latestVersion"
        }
    }
}

And here's a Ruby script that does the same thing (using the httparty gem):

require 'httparty'

query = ARGV[0]

class MavenCentral
    include HTTParty
    base_uri 'search.maven.org'

    def initialize(query, rows=20)
        @options = { query: {rows: rows, wt: 'json', q: query} }
    end 

    def artifacts
       self.class.get('/solrsearch/select', @options)
    end 
end

maven_central = MavenCentral.new(query)
maven_central.artifacts['response']['docs'].each do |doc|
    puts "#{doc['id']}:#{doc['latestVersion']}"
end
like image 7
bonh Avatar answered Oct 18 '22 15:10

bonh


There is an SBT plugin for this: sbt-search-maven-plugin

$ sbt "searchMaven log4j"
[info] Loading global plugins from ~/.sbt/0.13/plugins
[info] Set current project to foo (in build file:~/projects/)
[info] Results for log4j:
[info] "com.jkoolcloud.tnt4j.logger"      % "log4j"                % "0.1"
[info] "org.apache.logging.log4j"         % "log4j"                % "2.6.1"
[info] "org.darkphoenixs"                 % "log4j"                % "1.2.17"
[info] "log4j"                            % "log4j"                % "1.2.17"
[info] "de.huxhorn.lilith"                % "log4j"                % "0.9.41"
[info] "org.mod4j.org.eclipse.xtext"      % "log4j"                % "1.2.15"
[info] "org.apache.logging.log4j"         % "log4j-bom"            % "2.6.1"
[info] "org.apache.logging.log4j.samples" % "log4j-samples"        % "2.0.1"
[info] "org.apache.logging.log4j.osgi"    % "log4j-osgi"           % "2.0-rc1"
[info] "ro.fortsoft.log2j"                % "log2j-parent"         % "0.4"
[info] "ant"                              % "ant-apache-log4j"     % "1.6.5"
[info] "ant"                              % "ant-jakarta-log4j"    % "1.6.1"
[info] "plexus"                           % "plexus-log4j-logging" % "1.0"
[info] "org.apache.logging.log4j"         % "log4j-liquibase"      % "2.6.1"
[info] "org.apache.logging.log4j"         % "log4j-jul"            % "2.6.1"
[info] "org.apache.logging.log4j"         % "log4j-iostreams"      % "2.6.1"
[info] "org.apache.logging.log4j"         % "log4j-nosql"          % "2.6.1"
[info] "org.apache.logging.log4j"         % "log4j-jmx-gui"        % "2.6.1"
[info] "org.apache.logging.log4j"         % "log4j-taglib"         % "2.6.1"
[info] "org.apache.logging.log4j"         % "log4j-web"            % "2.6.1"
[success] Total time: 1 s, completed 24/06/2016 2:47:24 PM
like image 2
Synesso Avatar answered Oct 18 '22 14:10

Synesso