如何根据另一个插件的可用性修改插件中的设置和任务?

时间:2014-10-08 09:05:03

标签: sbt thrift scrooge

在我写的插件的build.sbt文件中,我有以下两行:

scroogeThriftDependencies in Compile := Seq("shared_2.10")

mappings in (Compile,packageBin) ~= { (ms: Seq[(File, String)]) =>
  ms filter { case (file, toPath) =>
    !toPath.startsWith(s"shared")
  }
}

但如果Build还包含Scrooge plugin,我只想这样做。如何实现这一目标?

我尝试过以下方法,但它不起作用:

lazy val onlyWithScrooge = taskKey[Unit]("Executes only if the Scrooge plugin is part of the build")

onlyWithScrooge := {
  val structure: BuildStructure = Project.extract(state.value).structure
  val pluginNames = structure.units.values.map { un => un.unit.plugins.detected }
  pluginNames.foreach(
    plugins => {
      plugins.plugins.modules.foreach {
        plugin =>
          if (plugin._1 == "com.twitter.scrooge.ScroogeSBT") {
            // i get here at least
            scroogeThriftDependencies in Compile := Seq("shared_2.10")
            mappings in (Compile,packageBin) ~= { (ms: Seq[(File, String)]) =>
              ms filter { case (file, toPath) =>
                !toPath.startsWith(s"shared")
              }
            }
          }
      }
    }
  )
}

(scroogeGen in Compile) <<= (scroogeGen in Compile) dependsOn onlyWithScrooge

0 个答案:

没有答案