【问题标题】:Nexus: How can I download latest minor version of artifact using nexus rest apiNexus:如何使用 nexus rest api 下载最新的次要版本的工件
【发布时间】:2017-06-28 11:46:39
【问题描述】:

我想从 Nexus 下载 最新的次要 版本的工件。如下所示:

http://local:8081/service/local/artifact/maven/content?g=com.mycompany&a=my-app&v=3.0.x

Nexus rest api 不接受 3.0.x3.0.* 等版本。

我不能使用 v=LATEST,因为它可能会更改主要版本。

有没有办法解决这个问题。

【问题讨论】:

    标签: maven deployment nexus devops artifact


    【解决方案1】:

    假设你使用 Nexus 2.x,你可以使用

    http://local:8081/service/local/lucene/search?repositoryId=someRep&a=my-app

    获取列出相关工件的 XML 响应。由此,您可以推断出您想要的版本。

    【讨论】:

    • 我想要一个可以下载工件的网址。
    【解决方案2】:

    通过添加 groovy 和 ant 解决了这个问题,并创建了一个宏来从 nexus 获取最新的次要版本。

    <taskdef name="groovy" classname="org.codehaus.groovy.ant.Groovy" classpath="Ant-library/groovy-all-2.2.1.jar"/>
    
    <macrodef name="fetchLatestMinor">
        <attribute name="group" default="NOT SET"/>
        <attribute name="artifact" default="NOT SET"/>
        <attribute name="majorVersion" default="NOT SET"/>
        <attribute name="repo" default="NOT SET"/>
        <attribute name="packaging" default="NOT SET"/>
        <attribute name="destination" default="NOT SET"/>
        <sequential>
            <property name="latestVersion" value=""/>
            <groovy>
                def url = "http://local:8081/nexus/service/local/lucene/search?a=@{artifact}&amp;v="+@{majorVersion}+".*-SNAPSHOT"
                def xml = url.toURL().text
                def root = new XmlParser().parseText(xml)
                properties["latestVersion"] = root.data.artifact[0].version.text()
                println root.data.artifact[0].version.text()
            </groovy>
            <get src="http://local:8081/nexus/service/local/artifact/maven/content?g=@{group}&amp;a=@{artifact}&amp;v=${latestVersion}&amp;r=@{repo}&amp;p=@{packaging}" dest="@{destination}"/>
        </sequential>
    </macrodef>
    
    <target name="run">
        <fetchLatestMinor group="<group_name>" artifact="<artifact_name>" majorVersion="2.0" repo="<repo_name>" packaging="war" destination="abc.war" />
    </target>
    

    【讨论】:

      猜你喜欢
      • 2011-12-16
      • 2017-01-22
      • 2012-06-06
      • 2013-01-24
      • 2012-08-26
      • 2021-10-12
      • 1970-01-01
      • 2018-09-12
      • 2018-01-14
      相关资源
      最近更新 更多