2
votes

I want to download latest minor version of an artifact from Nexus. Something like below:

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

Nexus rest api doesn't accept version like 3.0.x or 3.0.*.

I can't use v=LATEST because it might change the major version.

Is there any way available to solve this.

2

2 Answers

0
votes

Assuming you use Nexus 2.x, you can use

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

to get an XML response listing the relevant artifacts. From this, you can infer the version you want.

0
votes

Solved the problem by adding groovy with ant and created a macro to fetch latest minor version from 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>