Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 759
usercm Avatar asked Dec 06 '22 21:12

usercm


2 Answers

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>

like image 100
lance-java Avatar answered May 11 '23 06:05

lance-java


You would probably be interested in Ivy. It is a sub-project of Ant for dependency management. It is perfect for your situation because it can read Maven repositories and provides Ant tasks for downloading the published artifacts, constructing class paths from them, etc. It supports your use case of getting the most recent version of a dependency if you configure it to ask for the "latest.release" revision of the module.

like image 35
ChrisH Avatar answered May 11 '23 08:05

ChrisH