whysoserious
whysoserious

Reputation: 728

How to run a task before running tests

The following is a snippet from Build.scala:

object MyProject {

  val projectSettings = inConfig(Test)(
    testOptions += Tests.Setup { _ =>
      //subproject/runMain a.b.c.d.MainClass ??
    }
  }

}

I want to run a main class from another subproject before running tests. How can I do this?

Upvotes: 4

Views: 682

Answers (1)

Kenji Yoshida
Kenji Yoshida

Reputation: 3118

// build.sbt
lazy val a = project.settings(
  testOptions in Test += Tests.Setup { _ =>
    (runMain in Compile in b).toTask(" b.Main arg1 arg2").value
  }
)

lazy val b = project
// b/src/main/scala/Main.scala
package b

object Main {
  def main(args: Array[String]): Unit = {
    println("hello " + args.mkString(" "))
  }
}

Upvotes: 5

Related Questions