sbt-scalaxb is in the house
A big thanks to Max (@max4f) for writing a scalaxb plugin for sbt, and letting me pull it into the project.
If you're not using simple build tool, why?
Here are the steps to compile-xsd
task from sbt.
step 1. Plugins.scala
Add the following to your project/plugins/Plugins.scala
.
import sbt._ class Plugins(info: ProjectInfo) extends PluginDefinition(info) { val scalaxb = "org.scalaxb" % "sbt-scalaxb" % "0.6.0" val scalaToolsNexusSnapshots = "Scala Tools Nexus Snapshots" at "http://nexus.scala-tools.org/content/repositories/snapshots/" val scalaToolsNexusReleases = "Scala Tools Nexus Releases" at "http://nexus.scala-tools.org/content/repositories/releases/" }
step 2. Project.scala
Mix scalaxb.ScalaxbPlugin
trait into your Project.scala
.
import sbt._ class SampleAppProject(info: ProjectInfo) extends DefaultProject(info) with scalaxb.ScalaxbPlugin { }
Run reload
from sbt for the changes to take effect.
step 3. (optional) override defs
scalaxb.ScalaxbPlugin
is defined in a file under project/plugins/src_managed/sbt-scalaxb-x.x.x
, and defines the following methods you can override.
def generatedPackageName: String = "generated" def generatedPackageNames: Map[URI, String] = Map() def generatedClassPrefix: Option[String] = None def generatedParamPrefix: Option[String] = None def generatePackageDir: Boolean = true def generateWrapContents: Seq[String] = Nil
In your Project.scala
.
import sbt._ class SampleAppProject(info: ProjectInfo) extends DefaultProject(info) with scalaxb.ScalaxbPlugin { override def generatedPackageName = "xmlschema" }
step 4. xsd
directory
Make a directory called src/main/xsd/
and place your xsd files in there.
step 5. compile-xsd
Run the following from sbt.
> compile-xsd
This will generate scala files under src_generated/
directory, which is now a part of compilation.