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
下载你的依赖项。