1

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 插件时这样做。如何实现?

我尝试了以下方法,但没有奏效:

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
4

0 回答 0