【问题标题】:Get maven runtime dependencies in ant在ant中获取maven运行时依赖
【发布时间】:2023-04-04 09:59:01
【问题描述】:

我想在 ant 中从 maven 获取一组运行时依赖项。我正在使用 maven ant 任务。

我知道你可以通过作用域来限制依赖(see docs):

<artifact:dependencies filesetId="dependency.fileset" useScope="runtime">
  <artifact:pom file="pom.xml" id="myProject" />
</artifact:dependencies>

并且范围选项(来自文档)是:

•compile - Includes scopes compile, system and provided
•runtime - Includes scopes compile and runtime
•test - Includes scopes system, provided, compile, runtime and test

但是,我想获取运行时依赖项(即排除编译依赖项)。到目前为止我最好的想法是获取运行时依赖项和编译依赖项,并遍历运行时依赖项以找到那些不在编译依赖项中的依赖项,但我还没有弄清楚如何做到这一点。

有什么想法吗?

【问题讨论】:

    标签: ant maven dependencies


    【解决方案1】:

    所以这就是我试图获得运行时和编译文件集的区别(尽管这假设编译文件集中没有任何东西不在运行时文件集中)

    <artifact:dependencies filesetId="runtime" scopes="runtime">
      <artifact:pom file="pom.xml" id="myProject" />
    </artifact:dependencies>
    <artifact:dependencies filesetId="compile" scopes="compile">
      <artifact:pom file="pom.xml" id="myProject" />
    </artifact:dependencies>
    
    <difference id="difference" >
      <resources refid="runtime" />
      <resources refid="compile" />
    </difference>
    

    但是,这并没有产生我预期的结果,所以我做了以下操作,发现运行时文件集确实包含编译依赖项。

    <echo message="${toString:runtime}" />
    <echo message="${toString:compile}" />
    

    所以我可以只使用运行时范围...

    【讨论】:

    • 每个文件集将包含 ONLY 各自范围的依赖项。运行时依赖项不包含编译时依赖项。
    • 嘿!我建议您提交错误报告,要求他们修复文档。否则,这就是您所需要的。如果您觉得我的回答有用且正确,您可以接受。干杯! :)
    • 错误报告已在 maven ant 任务 JIRA 中提交
    【解决方案2】:

    你需要一些类似的东西:

    ...
    <artifact:pom id="maven.project" file="pom.xml"/>
    
    <artifact:dependencies useScope="runtime"
                           filesetId="dependencies.runtime"
                           pomRefId="maven.project"
                           settingsFile="${settings.xml}"/>
    ...
    

    然后你就可以像往常一样使用 dependencies.runtime 文件集了。

    我希望这更有意义。

    【讨论】:

      猜你喜欢
      • 2014-08-10
      • 2020-03-16
      • 2011-11-04
      • 1970-01-01
      • 2012-08-06
      • 2012-10-25
      • 1970-01-01
      • 1970-01-01
      • 2016-08-15
      相关资源
      最近更新 更多