This plugin is designed to allow one extract complete structure of SBT build in XML format. It is used in Intellij Scala plugin in order to support importing arbitrary SBT projects into IDEA.
It consists of two parts:
sbt-structure-coreis a set of datatypes and functions for their (de)serialization used as internal representation of SBT build in sbt-structuresbt-structure-extractoris SBT plugin that actually extracts information from SBT build
Add to your build.sbt
resolvers += Resolver.url("jb-bintray", url("http://dl.bintray.com/jetbrains/sbt-plugins"))(Resolver.ivyStylePatterns)
libraryDependencies += "org.jetbrains" %% "sbt-structure-core" % "4.1.0" // or later versionThen run extractor or get XML of the structure any other way and deserialize it:
import org.jetbrains.sbt._
import org.jetbrains.sbt.XmlSerializer._
val structureXml: Elem = XML.load(...)
val structure: Either[Throwable, StructureData] = structureXml.deserialize[StructureData]Extractor is run in several steps:
- Configure it by defining
sbt-structure-output-fileandsbt-structure-optionssettings inGlobalscope. - Create necessary tasks by applying extractor's jar to your project
- Run
dump-structuretask inGlobalscope
Here is an example of how to run extractor from SBT REPL:
> set SettingKey[Option[File]]("sbt-structure-output-file") := Some(file("structure.xml"))
> set SettingKey[String]("sbt-structure-options") := "prettyPrint download"
> apply -cp <path-to-extractor-jar> org.jetbrains.sbt.CreateTasks
> */*:dump-structuresbt-structure-options contains space-separated list of options.
sbt-structure-output-file points to a file where structure will be written; if
it is set to None then structure will be dump into stdout.
Available options to set in sbt-structure-options:
-
downloadWhen this option is set extractor will run
updatecommand for each project in build and build complete repository of all transitive library dependencies -
resolveClassifiers(requiresdownloadoption to be set as well)Same as
download+ downloading sources and javadocs for each transitive library dependency -
resolveSbtClassifiersThis option tells extractor to download sources and javadocs for SBT itself and plugins.
-
prettyPrintThis option will force extractor to prettify XML output. Useful for debug purposes.
-
Testing against all supported SBT versions can be done with
^ testcommand -
Testing against specific version of SBT, for example, 0.13.7:
^^ 0.13.7 test -
Selected tests can be run with
testOnlycommand, e.g.^ testOnly -- -ex "project name" -
To publish artifacts bump version in
build.sbtand run in SBT REPL:project core + publish project extractor ^^ 0.12 publish ^^ 0.13 publish