Skip to content

Instantly share code, notes, and snippets.

@mikemckibben
Created January 9, 2013 20:35
Show Gist options
  • Save mikemckibben/4496696 to your computer and use it in GitHub Desktop.
Save mikemckibben/4496696 to your computer and use it in GitHub Desktop.
An example of how to write a task that copies project dependencies to a directory.
TaskKey[Unit]("copy-plugin-dependencies") <<= (update) map {
(updateReport) =>
updateReport.select(Set("compile", "runtime")) map { jar =>
import java.util.jar.{JarFile, Manifest => JarManifest}
val jarFile = new JarFile(jar)
val jarAttributes = jarFile.getManifest().getMainAttributes()
val targetdir = file("plugins")
if (!targetdir.exists) targetdir.mkdir()
else if (!targetdir.isDirectory) error("%s is not a directory".format(targetdir))
for (bundleSymName <- Option(jarAttributes.getValue("Bundle-SymbolicName"));
version <- Option(jarAttributes.getValue("Bundle-Version")))
yield { (bundleSymName, version, jar, targetdir) }
} foreach { _ match {
case Some((bundleSymName, version, jar, targetdir)) => {
import java.nio.file.Files
Files.copy(jar.toPath, targetdir.toPath.resolve("%s_%s.jar".format(bundleSymName, version)))
}
case None => ()
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment