Bootstrap Apache Ivy

build.xml 中新增以下目標

<!-- Bootstrap ivy -->
<target name="ivy.bootstrap" description="Download Apache Ivy">

    <!-- Define the version to use -->
    <property name="ivy.version">2.4.0</property>

    <!-- Create directory if not exists -->
    <mkdir dir="${user.home}/.ant/lib" quiet="true" />

    <!-- Download it -->
    <echo message="Downloading Apache Ivy..." />
    <get dest="${user.home}/.ant/lib/ivy.jar" src="https://repo1.maven.org/maven2/org/apache/ivy/ivy/${ivy.version}/ivy-${ivy.version}.jar" />
</target>

執行任務 ant ivy.bootstrap 後,你現在可以使用 apache 常春藤解決依賴關係。

<target name="ivy.resolve" description="Resolve all artifacts.">

    <!-- Define lib driectory -->
    <property name="dir.lib">lib</property>

    <!-- Create directory if not exists -->
    <mkdir dir="${dir.lib}" />

    <!-- Configure -->
    <property name="ivy.dep.file" value="ivy.xml" />
    <ivy:settings file="ivysettings.xml" />

    <!-- Retrieve to a defined pattern -->
    <echo message="Resolving dependencies..." />
    <ivy:retrieve pattern="${dir.lib}/[artifact](-[classifier]).[ext]" />
</target>

ivy.xml 中定義你的資源

<ivy-module version="2.0">
        <info organisation="org.apache" module="java-build-tools"/>
        <dependencies>
                <dependency org="junit" name="junit" rev="4.11" />
                <dependency org="org.apache.commons" name="commons-compress" rev="1.9" />
        </dependencies>
</ivy-module>

ivysettings.xml 中的任何自定義儲存庫

<ivysettings>
    <settings defaultResolver="chain"/>
    <resolvers>
        <chain name="chain">
            <ibiblio name="central" m2compatible="true"/>
            <ibiblio name="github" m2compatible="true" root="http://github.com/"/>
        </chain>
    </resolvers>
</ivysettings>

通過執行 ant ivy.resolve 下載你的依賴項。