为什么默认运行任务不在自定义配置中选择设置?

时间:2014-07-27 12:42:07

标签: sbt

我使用commit 5b070b9dcc1dea25106573a86167517e5a8dc8d4中最新来源构建的sbt 0.13.6-SNAPSHOT

当我回复How to change value of setting for a custom configuration under play/sbt?时,问题出现了。

这是 build.sbt

lazy val Mock = config("mock") extend Compile

lazy val mock = inputKey[Unit]("run in mock mode")

lazy val mockSettings = inConfig(Mock) {
  Classpaths.configSettings ++
  Seq(
    unmanagedClasspath += baseDirectory.value / "mock-resources",
    mock <<= run in Mock,
    run <<= Defaults.runTask(fullClasspath in Mock, mainClass in Mock, runner in Mock)
  )
}

lazy val p = (project in file("src/")).configs(Mock).settings(
  mockSettings: _*
)

为什么自定义run配置需要自定义Mock任务?为什么不run选择unmanagedClasspath Mock配置?

请参阅以下会话:

> mock
[info] Running Hello
resource: file:/Users/jacek/sandbox/mock-config/src/mock-resources/a.properties
[success] Total time: 0 s, completed Jul 27, 2014 2:26:07 PM
> p/mock:run
[info] Running Hello
resource: file:/Users/jacek/sandbox/mock-config/src/mock-resources/a.properties
[success] Total time: 0 s, completed Jul 27, 2014 2:26:34 PM
> p/mock:mock
[info] Running Hello
resource: file:/Users/jacek/sandbox/mock-config/src/mock-resources/a.properties
[success] Total time: 0 s, completed Jul 27, 2014 2:27:01 PM

工作正常。

以下一行已从build.sbt中删除:

run <<= Defaults.runTask(fullClasspath in Mock, mainClass in Mock, runner in Mock)

这是构建定义的唯一更改。没有其他文件被触及。

> reload
[info] Loading global plugins from /Users/jacek/.sbt/0.13/plugins
[info] Set current project to mock-config (in build file:/Users/jacek/sandbox/mock-config/)
> p/mock:mock
[info] Running Hello
resource: null
[success] Total time: 0 s, completed Jul 27, 2014 2:28:31 PM
> p/mock:run
[info] Running Hello
resource: null
[success] Total time: 0 s, completed Jul 27, 2014 2:28:36 PM
> mock
[info] Running Hello
resource: null
[success] Total time: 0 s, completed Jul 27, 2014 2:28:39 PM

为什么默认run任务不适用于自定义Mock配置?

1 个答案:

答案 0 :(得分:0)

请使用已发布的版本提出问题,例如0.13.5。

如果您运行inspect命令,那么当您从run移除run <<= ....时,您应该清楚地确定了build.sbt任务:

p> inspect mock:run
[info] Input task: Unit
[info] Description:
[info]  Runs a main class, passing along arguments provided on the command line.
[info] Provided by:
[info]  {file:/Users/foo/sbt-so-24981062/}p/compile:run
[info] Defined at:
[info]  (sbt.Defaults) Defaults.scala:731

这是因为Classpaths.configSettings没有包含run任务。