11

是否可以通过常规 mvn 命令行客户端浏览中央存储库,并可能执行特定搜索?

例如:我想获取在其工件 ID 中具有“log4j”的所有工件的列表。

4

3 回答 3

7

我编写了一个小 Groovy 脚本来执行此操作:

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"
        }
    }
}

这是一个做同样事情的 Ruby 脚本(使用httpartygem):

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
于 2014-04-04T17:48:58.927 回答
2

为此有一个 SBT 插件: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
于 2016-06-24T04:48:09.220 回答
2
mvn -q com.jarcasting:search-maven-plugin:search -Dq="com google guava"

搜索 Maven 插件

于 2020-12-18T18:23:38.400 回答