これは、実行可能ファイルを作成する標準の Java ビルド ファイルですjar
。
ivy.xml
目的は、ANT プロパティとサードパーティの依存関係のファイルを組み合わせて、プロジェクト固有のものを管理することです。
<project xmlns:ivy="antlib:org.apache.ivy.ant" name="demo" default="build">
<property name="src.dir" location="src"/>
<property name="build.dir" location="build"/>
<property name="dist.dir" location="dist"/>
<property name="dist.jar" location="${dist.dir}/${ant.project.name}.jar"/>
<property name="dist.main.class" value="HelloWorld"/>
<target name="retrieve">
<ivy:resolve/>
<ivy:cachepath pathid="build.path" conf="build"/>
<ivy:cachepath pathid="runtime.path" conf="runtime"/>
</target>
<target name="compile" depends="retrieve">
<mkdir dir="${build.dir}/classes"/>
<javac srcdir="${src.dir}" destdir="${build.dir}/classes" classpathref="build.path"/>
</target>
<target name="build" depends="compile">
<ivy:retrieve pattern="${dist.dir}/lib/[artifact].[ext]"/>
<manifestclasspath property="jar.classpath" jarfile="${dist.jar}">
<classpath>
<fileset dir="${dist.dir}/lib" includes="*.jar"/>
</classpath>
</manifestclasspath>
<jar destfile="${dist.jar}" basedir="${build.dir}/classes">
<manifest>
<attribute name="Main-Class" value="${dist.main.class}"/>
<attribute name="Class-Path" value="${jar.classpath}"/>
</manifest>
</jar>
</target>
<target name="clean">
<delete dir="${build.dir}"/>
<delete dir="${dist.dir}"/>
</target>
</project>
Ivy ドキュメントで発見したように、cachepath
Ivy タスクは 2 つの ANT パスを管理するために使用されます。1 つはビルドの依存関係用で、もう 1 つは実行可能ファイルの実行時の依存関係用ですjar
。
Ivy の真の力は と呼ばれるものにありconfigurations
ます。jar
プロジェクトで定義できる s の単純な論理グループであることに気付くまで、最初は把握するのが難しいと感じました。この例には次の 2 つがありconfigurations
ます。
依存関係を に関連付ける方法を示すアイビー ファイルは次のconfigurations
とおりです。
<ivy-module version="2.0">
<info organisation="com.myspotontheweb" module="demo"/>
<configurations>
<conf name="build" description="Libraries needed to for compilation"/>
<conf name="runtime" extends="build" description="Libraries that need to be included with project jar" />
</configurations>
<dependencies>
<dependency org="commons-lang" name="commons-lang" rev="2.0" conf="build->default"/>
<dependency org="commons-cli" name="commons-cli" rev="1.0" conf="runtime->default"/>
</dependencies>
</ivy-module>
結論として、この例が Ivy を理解するのに役立つことを願っています。サードパーティの依存関係の管理という 1 つのことだけに集中する方法が気に入っています。