在我写的插件的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