【问题标题】:Ant Target to Expand Archives of DependencyAnt 目标扩展依赖档案
【发布时间】:2017-06-23 22:05:06
【问题描述】:

我有一个我正在尝试改进的 Ant/Ivy 构建过程。我需要解决依赖关系,然后将它们提取到特定文件夹。

依赖关系解析为$(build_root)/dependency/downloads/[configuration]/[artifactId]/[version]/ 位置,这工作正常。我最终在那个位置得到了一个.pom 和一个.tar.bz2 文件。

我想做的是对将依赖项的.tar.bz2 提取到目录进行更多控制。我们基本上试图通过控制提取.tar.bz2 输出的方式和位置来防止依赖项的libinc 发生冲突。

我们目前通过解决所有依赖项来做到这一点,然后有一个目标来盲目地扩展档案。

我们的解决步骤如下所示:

<target name="resolve">
    <ivy:retrieve pattern="${dependency.dir}/[conf]/[artifact]/[artifact]-[revision].[ext]" conf="*" />
    <condition property="archive.dir.present">
        <resourceexists>
            <file file="${dependency.dir}"/>
        </resourceexists>
    </condition>
    <antcall if:set="archive.dir.present" target="expand-archives"/>
</target>

注意对“expand-archives”目标的单独调用,如下所示:

<target name="expand-archives" description="Expand your Dependency Archives!">
    <for param="file">
        <path>
            <fileset dir="${dependency.dir}" includes="**/*.tar.bz2"/>
        </path>
        <sequential>
            <bunzip2 src="@{file}" dest="${dependency.dir}" />
        </sequential>
    </for>
    <!-- Follow the bunzip2 by the tar command to extract the tarball -->
    <for param="file">
        <path>
            <fileset dir="${dependency.dir}" includes="**/*.tar"/>
        </path>
        <sequential>
            <echo message="Processing: @{file}"/>
            <exec executable="tar" failonerror="true">
                <arg value="-C"/>
                <arg value="${dependency.dir}"/>
                <arg value="-xvf"/>
                <arg value="@{file}"/>
            </exec>
        </sequential>
    </for>
</target>

我想要的是 dest="${dependency.dir} 附加了一个依赖项的 artifactID。

有没有办法从检索中获取[artifact] 信息并将其传递给expand-archives 目标?

谢谢

【问题讨论】:

  • 我继续进行研究,看来我应该使用Triggers 来解决我的问题。一旦我得到它的工作,我会更新。欢迎提供更多建议/提示。

标签: maven ant ivy ant-contrib


【解决方案1】:

如果您对位于档案中的文件有依赖关系,也许您应该调查 ivy 中的 packager resolver

此解析器旨在下载 + 提取档案,然后使用 ANT sn-p 来决定您要依赖其中的哪些文件。乍一看很复杂,但一旦理解就非常强大。

以下示例显示了如何依赖包含在可下载“.tar.gz”存档中的 jar:

【讨论】:

    猜你喜欢
    • 2013-09-20
    • 2011-11-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-05-25
    • 2017-07-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多