【问题标题】:sbt programmatically resolve task scopesbt 以编程方式解析任务范围
【发布时间】:2017-11-26 23:19:52
【问题描述】:

如何以编程方式引用作用域键? IE。什么是程序等价物,例如scalafmt::test?

上下文:neo-sbt-scalafmt 定义了一个 TaskKey scalafmt 来格式化你的源,但它也定义了一个名为 test (https://github.com/lucidsoftware/neo-sbt-scalafmt/blob/master/sbt-scalafmt/src/main/scala/com/lucidchart/sbt/scalafmt/ScalafmtCorePlugin.scala#L143) 的范围,它只检查源是否符合预期的格式。

根据 SettingKey,TaskKey scalaFmt 在编译前被调用。我想介绍一个调用 scalafmt::test 的新 SettingKey。以下编译,但始终运行 scalafmt,而不是 scalafmt::test。

if (scalafmtOnCompile.value) scalafmt in resolvedScoped.value.scope
else if (scalafmtTestOnCompile.value) (test in scalafmt) in resolvedScoped.value.scope

https://github.com/lucidsoftware/neo-sbt-scalafmt/blob/master/sbt-scalafmt/src/main/scala/com/lucidchart/sbt/scalafmt/ScalafmtCorePlugin.scala#L170

我在 sbt gitter 频道上问了这个问题,然后在这里记录下来供下一个人使用。

【问题讨论】:

    标签: scope sbt task


    【解决方案1】:

    test in (resolvedScoped.value.scope in scalafmt.key)

    这基本上意味着:“采用现有范围,但将其置于 scalafmt 任务范围内,这就是我要使用的测试范围”

    感谢 Dale Wijnand 最初在 gitter 上提供的答案。

    【讨论】:

      猜你喜欢
      • 2017-10-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-04-16
      • 1970-01-01
      • 2020-11-06
      • 2015-07-21
      相关资源
      最近更新 更多