简体   繁体   中英

Using Maven in Ant for jar dependencies

Am new to Maven but am comfortable with the Ant, i like the way that maven downloads the jars and its dependencies, so i want to have maven dependency included in my Ant build script . I have seen how to use but here all the jar files are downloaded in .m2 folder, instead i need all the jars downloaded in the lib folder of my project . Can this be done or not,? if it can then can anybody please suggest me how to do it.

It is a very legit question.

Using maven ant tasks does use the generic maven repository location, simply because that would benefit all your maven projects, not just your local.

Maven uses per default a shared cache for all local project, simply because downloading commons-lang per project is sort of ridiculous.

You can specify a localRepository location for the execution (see http://maven.apache.org/ant-tasks/reference.html#localRepository ) if you like.

Also, as another user says, IVY is a good match for your usecase too. If you only need to download dependencies, then IVY does just that. Maven does it, but contains more, and it depends if you really want to explore these options.

I found a way to do this. You have to give filesetid in the artifact tag and use "filesetid" to copy to the given location

<target name="maven-test">
  <artifact:dependencies filesetid="build-dependency-jars">
    <dependency groupId="group_id" artifactId="artifact_id" version="version" />
  </artifact:dependencies>
        
<copy todir="./lib/">
    <fileset refid="build-dependency-jars" />
    <mapper type="flatten" />
</copy>

</target>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM