scala - 使 SBT 子项目中的编译操作依赖于其他子项目的编译而不将它们添加到类路径

标签 scala sbt

出于某些原因,我想编译子项目a 需要编译b 没有 b 出现在 a 的类路径中。相反,a 类将通过动态加载它们来访问(是的,这通常是一个坏主意,但这是一个要求)。以前的 SBT 版本曾问过这个问题,例如How to depend on other tasks and do your code in SBT 0.10? . 我试过了

(compile in (a, Compile)) <<= (compile in (b, Compile), compile in (a, Compile)) {
  (_, out) => out
}

(基于上述答案)和

(compile in (a, Compile)) := {
  (compile in (b, Compile)).value
  (compile in (a, Compile)).value
}

两者似乎都不适用于 SBT 0.13.9。

最佳答案

您可以使用 dependsOn 运算符来覆盖模块 a 设置中的默认 compile 行为。

lazy val a = Project(...)
    .settings(compile in Compile <<= compile in Compile dependsOn (compile in Compile in b))

关于scala - 使 SBT 子项目中的编译操作依赖于其他子项目的编译而不将它们添加到类路径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37679708/

相关文章:

scala - SBT:如何获取IntegrationTest中的所有定义?

scala - 如果我将 Option 传递给它,Scala for-yield 可以返回 None 吗?

scala - sbt 插件动态加载用户定义的代码?

regex - 为什么 RegexTest 有一个 main 方法?

scala - SBT:如何在 Sonatype 上发布聚合项目和所有模块?

scala - 使用 <<= 定义的 sbt 任务与使用 := that references another setting's . 值定义的任务有何不同?

scala - 我可以从代码访问我的 Scala 应用程序的名称和版本(在 SBT 中设置)吗?

scala - 分组 ScalaTest 测试并按顺序运行

scala - Akka 事件总线教程

scala - 尝试编译播放模板项目时 Unresolved 依赖项 : sbt-plugin;2. 7.0