LoginSignup
0
0

More than 5 years have passed since last update.

sbt で compile や runMain タスクを実行する際に、先に ant のタスクを実行させる

Posted at

概要

タイトルのまんまです。

設定

ant のプラグインを追加します。

project/plugins.sbt
addSbtPlugin("de.johoop" % "ant4sbt" % "1.1.2") // 追加

build.xml にメッセージを表示するだけの ant task を定義します。

build.xml
<project basedir=".">
    <target name="testTask">
        <echo message="ant testTask called"/>
    </target>
</project>

build.sbt で先ほどの ant task を取り込み、compile, runMain タスクを依存させます。

build.sbt
import de.johoop.ant4sbt.Ant4Sbt._

name := "sbtAntSample"

version := "1.0"

scalaVersion := "2.11.5"


antSettings

antBuildFile := baseDirectory.value / "build.xml"

antBaseDir := baseDirectory.value

addAntTasks("testTask")

compile <<= (compile in Compile).dependsOn(antTaskKey("testTask"))

runMain <<= (runMain in Compile).dependsOn(antTaskKey("testTask"))

Sample クラスをテキトーに作成します。

src/main/scala/Sample.scala
object Sample {
  def main(args:Array[String]): Unit = {
    println("main called")
  }
}

実行してみる

$ sbt "runMain Sample"
Listening for transport dt_socket at address: 9999

...

[info] testTask:
[info]      [echo] ant testTask called
...

[info] Compiling 1 Scala source to ...
[info] Running Sample
main called
[success] 

ant のタスクが実行されています。

0
0
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
0
0