maven,通过命令行客户端浏览中央存储库

问题描述 投票:0回答:4

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

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

maven-2
4个回答
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 脚本,它可以做同样的事情(使用

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

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

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

搜索-maven-插件


0
投票

询问“mvn命令行客户端”。没有任何脚本!仅 mvn 命令行客户端。

© www.soinside.com 2019 - 2024. All rights reserved.