Scalaのコンパイルを行うタスク。
scalacはAnt標準には含まれていないので、Scalaのコンパイルライブラリーからタスクを定義する必要がある。
また、コンパイルの実行にはScalaのランタイムライブラリーが必要となる。
<target name="init">
<property name="scala-library.jar" value="${env.SCALA_HOME}/lib/scala-library.jar" />
<taskdef resource="scala/tools/ant/antlib.xml">
<classpath>
<pathelement location="${env.SCALA_HOME}/lib/scala-compiler.jar" />
<pathelement location="${scala-library.jar}" />
</classpath>
</taskdef>
</target>
<target name="build" depends="init">
<scalac srcdir="${src.dir}" destdir="${build.dir}">
<classpath>
<pathelement location="${scala-library.jar}" />
<pathelement location="${build.dir}" />
</classpath>
</scalac>
</target>
| 属性 | 説明 | scalac相当 | 更新日 |
|---|---|---|---|
| srcdir | ソースファイルのディレクトリー。 | ||
| destdir | コンパイル先のディレクトリー。 | -d | |
| classpathref | クラスパスの指定。この中に${scala-library.jar}も含める。 | ||
| deprecation | trueにすると、使用された非推奨な式の詳細を表示する。 | -deprecation | 2011-09-03 |
| タグ(使用例) | 説明 |
|---|---|
<src path="../src"
/> |
scalaファイルの存在しているディレクトリー。 |
<include name="**/*.scala"
/> |
コンパイル対象ファイル。 |
<exclude name="**/*Test.scala"/> |
コンパイルから除外するファイル。 |
<classpath refid="classpath" /> |
クラスパスの指定。この中に${scala-library.jar}も含める。 |
Asakusa Frameworkのライブラリーを使いつつScalaのソースをコンパイルする例。
この例ではScalaのライブラリーはEclipseのScalaプラグインのものを使用している。
build.xml:
<?xml version="1.0" encoding="UTF-8"?> <project name="afwhs1scala" default="build" basedir="."> <property name="src.dir" value="../src" /> <property name="build.dir" value="../classes" />
<property name="M2_REPO" location="C:/Documents and Settings/hishidama/.m2/repository" />
<path id="asakusa.classpath">
<pathelement location="${M2_REPO}/com/asakusafw/asakusa-runtime/0.2.1/asakusa-runtime-0.2.1.jar" />
<pathelement location="${M2_REPO}/com/asakusafw/asakusa-thundergate-vocabulary/0.2.1/asakusa-thundergate-vocabulary-0.2.1.jar" />
<pathelement location="${M2_REPO}/com/asakusafw/asakusa-dsl-vocabulary/0.2.1/asakusa-dsl-vocabulary-0.2.1.jar" />
</path>
<target name="init">
<property name="scala-library.home" location="C:\eclipse\configuration\org.eclipse.osgi\bundles\327\1\.cp" />
<property name="scala-compiler.home" location="C:\eclipse\configuration\org.eclipse.osgi\bundles\326\1\.cp" />
<property name="scala-library.jar" value="${scala-library.home}/lib/scala-library.jar" />
<path id="build.classpath">
<pathelement location="${scala-library.jar}" />
<path refid="asakusa.classpath" />
<pathelement location="${build.dir}" />
</path>
<taskdef resource="scala/tools/ant/antlib.xml">
<classpath>
<pathelement location="${scala-compiler.home}/lib/scala-compiler.jar" />
<pathelement location="${scala-library.jar}" />
</classpath>
</taskdef>
</target>
<target name="build" depends="init">
<scalac srcdir="${src.dir}" destdir="${build.dir}" classpathref="build.classpath">
<include name="**/*.scala" />
</scalac>
</target>
</project>