sbt-scalaxb
This page describes adding scalaxb task to your sbt project. (The page describing sbt-scalaxb for sbt 0.7 is moved)
step 1,2,3,4-A. automate using g8
The following steps has been scripted into a giter8 template called eed3si9n/scalaxb.g8. For a quick project, run the following after installing giter8.
$ g8 eed3si9n/scalaxb
After asking you for a project name, the above sets up a nearly empty sbt project with sbt-scalaxb pre-installed. A convenient method to start using scalaxb.
If you want to do add scalaxb to an existing project, keep reading.
step 1-B. plugins.sbt
Put this in your project/plugins.sbt (for sbt 0.11.x):
addSbtPlugin("org.scalaxb" % "sbt-scalaxb" % "X.X") resolvers ++= Seq( "sonatype-public" at "https://oss.sonatype.org/content/repositories/public", "repo.codahale.com" at "http://repo.codahale.com")
Put this in your project/plugins/build.sbt (for sbt 0.10.1):
libraryDependencies <+= (sbtVersion) { sv => "org.scalaxb" %% "sbt-scalaxb" % ("sbt" + sv + "_X.X") }
step 2-B. build.sbt
Put this at the top of your build.sbt:
import ScalaxbKeys._
Then writing
seq(scalaxbSettings: _*)
loads scalaxb task after running reload. The default setting scalaxbSettings scopes scalaxb task into Compile configuration, which compiles all xsd files from src/main/xsd and wsdl files under src/main/wsdl.
step 3-B. directory structure
Make src/main/xsd and src/main/wsdl directory and place your schema document there.
step 4-B. (optional) basic settings
Settings for the way scalaxb generates the code can be customized by rewiring the settings scoped under scalaxb task and Compile configuration:
packageName in scalaxb in Compile := "packagename"
Additionally, scalaxb can automatically be invoked as part of complication as follows for sbt 0.11+:
sourceGenerators in Compile <+= scalaxb in Compile
For sbt 0.10 use:
sourceGenerators in Compile <+= (scalaxb in Compile).identity
Here is the list of settings that may be rewired:
sourceManaged sources xsdSource wsdlSource
packageName packageNames attributePrefix classPrefix paramPrefix
wrapContents chunkSize packageDir generateRuntime laxAny
protocolFileName protocolPackageName scalaxbConfig logLevel
step 5. (optional) custom configurations
If you wish to use scalaxb task multiple times in a project, you can do so by creating custom configurations in build.scala.
val Xsd = config("xsd") extend(Compile) val Wsdl = config("wsdl") extend(Compile) lazy val appSettings = buildSettings ++ inConfig(Xsd)(baseScalaxbSettings ++ inTask(scalaxb)(customScalaxbSettings("xmlschema"))) ++ inConfig(Wsdl)(baseScalaxbSettings ++ inTask(scalaxb)(customScalaxbSettings("wsdl11"))) def customScalaxbSettings(base: String): Seq[Project.Setting[_]] = Seq( sources <<= xsdSource map { xsd => Seq(xsd / (base + ".xsd")) }, packageName := base, )
Now these tasks would be invoked as follows:
> xsd:scalaxb
> wsdl:scalaxb
