简体   繁体   English

在 Ant 中使用 Maven 获取 jar 依赖项

[英]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 .我是 Maven 新手,但对 Ant 很满意,我喜欢 maven 下载 jars 及其依赖项的方式,所以我希望在我的 Ant 构建脚本中包含 maven 依赖项 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 .我已经看到了如何使用,但是这里所有的 jar 文件都下载到.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 ant 任务确实使用了通用的 maven 存储库位置,仅仅是因为这将使您的所有 maven 项目受益,而不仅仅是您的本地项目。

Maven uses per default a shared cache for all local project, simply because downloading commons-lang per project is sort of ridiculous. Maven 默认为所有本地项目使用共享缓存,因为每个项目下载 commons-lang 有点荒谬。

You can specify a localRepository location for the execution (see http://maven.apache.org/ant-tasks/reference.html#localRepository ) if you like.如果您愿意,您可以指定执行的 localRepository 位置(请参阅http://maven.apache.org/ant-tasks/reference.html#localRepository )。

Also, as another user says, IVY is a good match for your usecase too.此外,正如另一位用户所说, IVY也非常适合您的用例。 If you only need to download dependencies, then IVY does just that.如果您只需要下载依赖项,那么IVY就是这样做的。 Maven does it, but contains more, and it depends if you really want to explore these options. Maven 做到了,但包含更多,这取决于您是否真的想探索这些选项。

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您必须在工件标记中提供filesetid并使用“filesetid”复制到给定位置

<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>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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