LoginSignup
2
2

More than 5 years have passed since last update.

Apache Ivy の自動ダウンロード

Posted at

==========================

Apache Ivy を使用することで、依存ライブラリである *.jar ファイルを SCM にコミットしなくても良くなった。この流れで、ivy.jar も SCM にコミットせず、各開発者が手動ダウンロードしなくても良いようにしてみた。

需要がないだろうけど、以下にそれを晒す。

build.properties
apache.mirror.site = http://ftp.riken.jp/net/apache
#apache.mirror.site = http://ftp.jaist.ac.jp/pub/apache
#apache.mirror.site = http://ftp.kddilabs.jp/infosystems/apache
#apache.mirror.site = http://ftp.yz.yamagata-u.ac.jp/pub/network/apache
#apache.mirror.site = http://ftp.tsukuba.wide.ad.jp/software/apache
#apache.mirror.site = http://ftp.meisei-u.ac.jp/mirror/apache/dist

# コミットしないように .gitignore や svn:ignore に追加する
target.dir = target

ivy.version = 2.4.0
ivy.dir     = ${target.dir}/vendor/ivy
ivy.lib.dir = ${ivy.dir}/${ivy.version}
ivy.url     = ${apache.mirror.site}/ant/ivy/${ivy.version}/apache-ivy-${ivy.version}-bin.zip
build.xml
    <target name="-ivy" depends="-ivy.jar">
      <taskdef resource="org/apache/ivy/ant/antlib.xml"
               uri="antlib:org.apache.ivy.ant">
        <classpath>
          <fileset dir="${ivy.lib.dir}">
            <include name="*.jar" />
          </fileset>
        </classpath>
      </taskdef>
    </target>

    <target name="-ivy.jar"
            depends="-downloaded.ivy.jar"
            unless="downloaded.ivy.jar">
      <!-- 旧バージョンを削除し、指定したバージョンのivy.jarをダウンロードする -->
      <delete dir="${ivy.dir}" />
      <mkdir  dir="${ivy.lib.dir}" />

      <get src="${ivy.url}"
           dest="${target.dir}/ivy.zip" />
      <unzip src="${target.dir}/ivy.zip"
             dest="${ivy.lib.dir}">
        <patternset>
          <include name="*/*.jar" />
        </patternset>
        <mapper type="flatten" />
      </unzip>

      <delete file="${target.dir}/ivy.zip" />
    </target>

    <target name="-downloaded.ivy.jar">
      <!-- 指定したバージョンの ivy.jar をダウンロード済みか判定する -->
      <available property="downloaded.ivy.jar"
                 file="${ivy.lib.dir}/ivy-${ivy.version}.jar" />
    </target>

あとは次のように属性 depends 等でターゲット -ivy を実行すれば良いだけ。

build.xml
    <target name="-main.classes"
            depends="-ivy">
        <mkdir dir="${main.classes.dir}" />
        <ivy:cachepath pathid="main.classpath" conf="runtime"/>
        <javac destdir="${main.classes.dir}" includeantruntime="false"
               encoding="UTF-8"
               debug="true" debuglevel="source,lines">
            <classpath refid="main.classpath" />
            <src path="${main.java.dir}" />
        </javac>
    </target>
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