How to run a task before running tests

Below 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 the main class from another subproject before running tests. How can i do this?

+3


source to share


1 answer


// 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(" "))
  }
}

      

+4


source







All Articles