【问题标题】:Minimum config to use Ivy to set a path in an Ant build?使用 Ivy 在 Ant 构建中设置路径的最低配置?
【发布时间】:2017-07-07 05:34:03
【问题描述】:

我想使用在工件中定义的 Ant 任务。该工件存在于主要的 Maven 存储库中并具有一些依赖项。

我想用 Ivy 和 Ant 来:

  1. 声明对该工件的依赖及其传递依赖,以便在脚本运行时解决它们。
  2. 检索所有 jar 文件作为 Ant 路径,我可以将其输入 Ant 的 taskdef。
  3. 在构建脚本的其他部分中引用该组已解析的 jar 文件。

到目前为止,我发现的文档并未针对此用例进行优化。相反,它建议编写文件 ivy.xml、ivysettings.xml;我不喜欢这样,依赖项太小了,我想把所有东西都放在一个构建脚本中。

有什么想法吗?

【问题讨论】:

    标签: ant ivy


    【解决方案1】:

    ivy cachepath task 是一个解析任务,可用于创建 ANT 路径。可能不为人所知的是,这个解析任务也可以内联使用,换句话说,您可以直接指定依赖关系,而无需 ivy 文件。

    <ivy:cachepath pathid="tasks.path">
        <dependency org="org.codehaus.groovy" name="groovy-all" rev="2.4.7" conf="default"/>
    </ivy:cachepath>
    

    有关使用 ivy 文件管理多个类路径的相关答案:

    示例

    以下示例是通过演示 ivy 下载与 groovy 任务相关联的 jar 来稍微做作的。我还包含了一个实用程序目标,用于安装 ivy jar。

    build.xml

    <project name="demo" default="build" xmlns:ivy="antlib:org.apache.ivy.ant">
    
        <available classname="org.apache.ivy.Main" property="ivy.installed"/> 
    
        <!--
        ============
        Main targets 
        ============
        -->
        <target name="resolve" depends="install-ivy">
            <ivy:cachepath pathid="tasks.path">
                <dependency org="org.codehaus.groovy" name="groovy-all" rev="2.4.7" conf="default"/>
            </ivy:cachepath>
        </target>
    
        <target name="build" depends="resolve">
            <taskdef name="groovy" classname="org.codehaus.groovy.ant.Groovy" classpathref="tasks.path"/>
    
            <groovy>
              ant.echo "Hello world"
            </groovy>
        </target>
    
        <!--
        ==================
        Supporting targets
        ==================
        -->
        <target name="install-ivy" description="Install ivy" unless="ivy.installed">
            <mkdir dir="${user.home}/.ant/lib"/>
            <get dest="${user.home}/.ant/lib/ivy.jar" src="http://search.maven.org/remotecontent?filepath=org/apache/ivy/ivy/2.4.0/ivy-2.4.0.jar"/>
            <fail message="Ivy has been installed. Run the build again"/>
        </target>
    
        <target name="clean" description="Cleanup build files">
            <delete dir="${build.dir}"/>
        </target>
    
        <target name="clean-all" depends="clean" description="Additionally purge ivy cache">
            <ivy:cleancache/>
        </target>
    
    </project>
    

    【讨论】:

      猜你喜欢
      • 2012-09-04
      • 2020-09-04
      • 2012-09-04
      • 2011-01-25
      • 2020-10-04
      • 2011-06-23
      • 2011-07-30
      • 2012-10-22
      • 1970-01-01
      相关资源
      最近更新 更多