Maven – Download jars from nexus using ant build tool as done automatically in Maven

antdownloadjarmavennexus

I have a build.xml(ant based) which requires some jar from nexus to get copied in existing lib folder. i.e when it builds it should copy the jar from nexus with some version defined & then copy in lib & do compilation.
like happen in maven we define the artifact & its version . If changed will automatically download it from maven repo.
how can i do this in ant based builds?

experts pls advice.

Best Answer

I have taken the example listed in this thread one step further and created a macrodef to clean things up a bit for re-use. See below for downloading two artifacts from nexus (one snapshot, one release).

<project>
<target name="get-all">
    <mkdir dir="lib" />
    <nexus-get 
        groupId="foo.bar" 
        artifactId="some-artifact"
        version="1.0.28"
        repo="releases"
        extension="jar" 
        dest="lib" 
    />

    <nexus-get 
        groupId="foo.bar" 
        artifactId="another-artifact"
        version="1.0.0-SNAPSHOT"
        repo="snapshots"
        extension="jar" 
        dest="lib" 
    />
</target>

<macrodef name="nexus-get">
    <attribute name="groupId"/>
    <attribute name="artifactId"/>
    <attribute name="version"/>
    <attribute name="repo"/>
    <attribute name="extension"/>
    <attribute name="dest"/>

    <sequential>
        <get src="http://my-nexus:9999/nexus/service/local/artifact/maven/redirect?r=@{repo}&amp;g=@{groupId}&amp;a=@{artifactId}&amp;v=@{version}&amp;e=@{extension}" dest="@{dest}/@{artifactId}.@{extension}" usetimestamp="true" />
    </sequential>
</macrodef>