首页 > 解决方案 > 在 0.13.x 中默认在子项目的上下文中执行“运行”

问题描述

我曾经能够在我的build.sbt文件中使用以下内容来允许我run在我的root项目中执行命令,但运行命令只会在我的migrations项目的上下文中运行:

lazy val root = project.dependsOn(rest,migrations).settings(publish := { }).disablePlugins(RevolverPlugin, AssemblyPlugin)
lazy val rest = project.enablePlugins(BuildInfoPlugin)
lazy val migrations = project.dependsOn(rest).settings(mainClass in (Compile, run) := Some("com.myapp.Migrations"), fork in run := true).disablePlugins(RevolverPlugin)

run in Compile <<= (run in Compile in migrations)

然后我会run像这样执行:

> run up

(psup是要传递给的参数com.myapp.Migrations

但是,当更新到 sbt v0.13.17 时,我现在收到警告:

See http://www.scala-sbt.org/0.13/docs/Migrating-from-sbt-012x.html
run in Compile <<= (run in Compile in migrations)

在引用的 url 中,似乎表明我可以替换<<=with :=,但是如果我像这样更改它:

run in Compile := (run in Compile in migrations)

然后我输入run upsbt,我得到错误:

[error] Expected ID character
[error] Not a valid command: run (similar: plugin, new)
[error] Expected project ID
[error] Expected configuration
[error] Expected ':' (if selecting a configuration)
[error] Expected key
[error] Expected '::'
[error] Expected end of input.
[error] run up
[error]    ^

有谁知道我如何更新上述行以符合 0.13.x 并且仍然按预期工作?

标签: sbt

解决方案


https://www.scala-sbt.org/0.13/docs/Migrating-from-sbt-012x.html#Migrating+with

使用 InputKey 迁移

当使用 InputKey 而不是:

run <<= docsRunSetting

迁移时不能使用 .value 而是 .evaluated:

run := docsRunSetting.evaluated

在你的情况下尝试run in Compile := (run in Compile in migrations).evaluated


推荐阅读