2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Ant で Ivy の jar をダウンロードさせて、その jar からタスクを定義する

Posted at

依存性の解決に Apache Ivy を使っているが、コードの共有者が Ant を入れていても Ivy は入れていない場合に、Ivy インストールのため最初に実行してもらうタスクのマークアップです。

build.xml
<project xmlns:ivy="antlib:org.apache.ivy.ant">
    <condition property="ivy.home" value="${env.IVY_HOME}">
        <isset property="env.IVY_HOME" />
    </condition>
    <property name="ivy.home" value="${user.home}/.ivy2" />
    <property name="ivy.install.dir" value="${ivy.home}/lib" />
    <property name="ivy.install.dest" value="${ivy.install.dir}/ivy.jar" />

    <target name="-check-ivy-user-installed" description="check ivy jar file existence on user's ivy home">
        <available file="${ivy.install.dest}" property="ivy.install.dest.exisits" />
    </target>

    <target name="-taskdef-user-ivy" depends="-check-ivy-user-installed" if="ivy.install.dest.exisits">
        <path id="ivy.install.path">
            <fileset dir="${ivy.install.dir}" includes="*.jar" />
        </path>
        <taskdef resource="org/apache/ivy/ant/antlib.xml"
                 uri="antlib:org.apache.ivy.ant" classpathref="ivy.install.path"/>
    </target>

    <target name="install-ivy" description="Download Ivy jar file to ivy home">
        <property name="ivy.install.version" value="2.2.0" />
        <property name="ivy.install.src"
            value="http://repo1.maven.org/maven2/org/apache/ivy/ivy/${ivy.install.version}/ivy-${ivy.install.version}.jar" />

        <mkdir dir="${ivy.install.dir}" />
        <get src="${ivy.install.src}" dest="${ivy.install.dest}" usetimestamp="true"/>
    </target>

    <target name="clean-ivy" description="Delete Ivy jar file from ivy home">
        <delete file="${ivy.install.dest}" />
    </target>

    <!-- sample task to use user ivy -->
    <target name="resolve" description="Resolve dependency" depends="-taskdef-user-ivy">
        <ivy:resolve />
    </target>
</project>
usage
ant install-ivy

一方で、これをプロジェクトのビルドファイルに含めるのは、あまり合理的ではないかもしれません。

2
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?