简体   繁体   English

sbt:在多项目构建中,如何从项目A调用项目B的任务?

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

I have a Build.scala for multiple projects. 我有多个项目的Build.scala。

Two of the projects use ScalaJs cross-compilation. 其中两个项目使用ScalaJs交叉编译。

One of the other projects is a pure Scala project, that wants access to some of the ScalaJs-generated Javascript files. 其他项目之一是纯Scala项目,该项目希望访问一些ScalaJs生成的Javascript文件。

(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.) (最好只从ScalaJs项目访问这些.js文件,但是我正在尝试在现有项目层次结构的顶部添加使用ScalaJs实现的功能,在这些现有项目层次结构中已经实现了REST API,无需大幅度更改后者。)

Ideally, I'd like to add a new task to the "app" project, that 理想情况下,我想向“ app”项目中添加一个新任务,

  1. invokes (fastOptJS or fullOptJS) and compile on the ScalaJs projects 调用(fastOptJS或fullOptJS)并在ScalaJs项目上编译
  2. copies the .js files that were built in thos eprojects, to the app project 将在esprojects中内置的.js文件复制到app项目中
  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. 我曾考虑过在ScalaJs项目中扩展fastOptJS / fullOptJS,以将.js文件“推送”到他们想要在应用程序项目中放置的位置,但这让人倒退。 (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": 最简单的方法是将fastOpt添加到“ 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: 如果需要将文件放置在特殊位置,则可以将资源生成器添加到复制fastOpt文件的“ app”项目中:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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