简体   繁体   中英

sbt: In a multi-project build, how to invoke project B's task from project A?

I have a Build.scala for multiple projects.

Two of the projects use ScalaJs cross-compilation.

One of the other projects is a pure Scala project, that wants access to some of the ScalaJs-generated Javascript files.

(It might be preferable to only access those .js files from the ScalaJs projects, but I'm experimenting with adding features implemented with ScalaJs on top of an existing project hierarchy, where a REST API is already implemented in one of those existing projects, without drastically changing the latter.)

Ideally, I'd like to add a new task to the "app" project, that

  1. invokes (fastOptJS or fullOptJS) and compile on the ScalaJs projects
  2. copies the .js files that were built in thos eprojects, to the app project
  3. invokes compile on the app project

I know how to extend a task by invoking another, but I don't know how to do it when the invoked task isn't in the same project.

Is this possible?

Or is there another way to do this?

I thought about extending fastOptJS/fullOptJS in the ScalaJs projects, to "push" the .js files out to where they want to go in the app project, but that feels backwards. (Maybe the easiest way to do this though?)

Thanks for any help, --Steve

The simplest way to do that is by simply adding the fastOpt to the resources in the settings of "app":

resources in Compile += (fastOptJS in Compile in scalaJSProject).value.data

If you need the file to be in a special location, you can add a resource generator to your "app" project that copies the fastOpt file:

resourceGenerators in Compile += Def.task {
  val trg = (resourceManaged in Compile).value / "jsStuff.js"
  IO.copyFile((fastOptJS in Compile in scalaJSProject).value.data, trg)
  Seq(trg)
}.taskValue

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM