1

In the build.sbt file of a plugin I have written I have the following two lines:

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

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

but I only want to do this if the Build also contains the Scrooge plugin. How can this be accomplished?

I have tried the approach below but it didn't work:

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
Jacek Laskowski
  • 72,696
  • 27
  • 242
  • 420
reikje
  • 2,850
  • 2
  • 24
  • 44
  • You're developing a plugin that based on a condition adds some additional settings? And the condition is an existence of a plugin - the Scrooge plugin? Is my understanding correct? – Jacek Laskowski Oct 09 '14 at 06:47
  • @JacekLaskowski yes correct. Basically, if the Scrooge plugin is part of the build, I want to set scroogeThriftDependencies and exclude some generated code from mappings. This will be part of a common plugin that all of our projects will include. Otherwise every project needs to add these 2 modifications to their own build.sbt files. – reikje Oct 09 '14 at 08:52

0 Answers0