Skip to content

Instantly share code, notes, and snippets.

@teigen
Created December 13, 2011 08:14
Show Gist options
  • Save teigen/1471192 to your computer and use it in GitHub Desktop.
Save teigen/1471192 to your computer and use it in GitHub Desktop.
import sbt._
import Keys._
object build extends Build {
// usage example
lazy val example = Project(
"example",
file("."),
settings = Defaults.defaultSettings ++ Nucleus.settings ++ Seq(
scalaVersion := "2.9.1",
name := "example",
libraryDependencies ++= Seq(
"org.datanucleus" % "datanucleus-core" % "3.0.1",
"org.datanucleus" % "datanucleus-api-jdo" % "3.0.1",
"javax.jdo" % "jdo-api" % "3.0"
)
)
)
}
// should be fairly simple to turn this into a plugin
// https://github.com/harrah/xsbt/wiki/Plugins
object Nucleus {
// defines our own ivy config that wont get packaged as part of your app
// notice that it extends the Compile scope, so we inherit that classpath
val Config = config("nucleus") extend Compile
// our task
val enhance = TaskKey[Unit]("enhance")
// impementation
val settings:Seq[Project.Setting[_]] = Seq(
// let ivy know about our "nucleus" config
ivyConfigurations += Config,
// add the enhancer dependency to our nucleus ivy config
libraryDependencies += "org.datanucleus" % "datanucleus-enhancer" % "3.0.1" % Config.name,
// fetch the classpath for our nucleus config
// as we inherit Compile this will be the fullClasspath for Compile + "datanucleus-enhancer" jar
fullClasspath in Config <<= (classpathTypes in enhance, update).map{(ct, report) =>
Classpaths.managedJars(Config, ct, report)
},
// add more parameters as your see fit
enhance in Config <<= (fullClasspath in Config, runner, streams).map{(cp, run, s) =>
// the classpath is attributed, we only want the files
val classpath = cp.files
// the options passed to the Enhancer...
val options = Seq("-v")
// run returns an option of errormessage
val result = run.run("org.datanucleus.enhancer.DataNucleusEnhancer", classpath, options, s.log)
// if there is an errormessage, throw an exception
result.foreach(sys.error)
}
)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment