Home

Awesome

official JetBrains project Version Build Status Discord Gitter

sbt-structure

This plugin extracts the structure of an sbt build in XML format. It is used in Intellij Scala plugin in order to import arbitrary sbt projects into IDEA.

Problems?

Please report any issues related to sbt-structure in IntelliJ on the IntelliJ Scala YouTrack project.

Project structure

Note: extractor is packaged as a fat jar, by compiling the sources of core and including the output .class files in the resulting jar. This packaging structure is implicitly expected by the Intellij Scala plugin, due to how the jar is injected in sbt for extracting the information of a sbt build. The shared sources are contained in the shared directory and linked in the extractor and core modules, in order to create a source dependency that can be recognized by IDEA.

Usage

Core

Add to your build.sbt

libraryDependencies += "org.jetbrains.scala" %% "sbt-structure-core" % "<version>"

Then 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

Extractor can be run as a regular sbt plugin, or loaded into the build during an sbt shell session.

As an sbt plugin

The quickest way to try out the extractor is by adding it to your build in project/plugins.sbt as an sbt plugin:

addSbtPlugin("org.jetbrains.scala" % "sbt-structure-extractor" % "<version>", "1.3")

Then from the sbt shell run:

*/*:dumpStructure

This will output the xml directly to the shell.

To write the xml to a file, run:

set org.jetbrains.sbt.StructureKeys.sbtStructureOptions in Global := "prettyPrint download"
*/*:dumpStructureTo structure.xml

The dumpStructure task uses the settings described below, the dumpStructureTo task takes sbtStructureFile as parameter instead.

Sideloading

This is the way Intellij-Scala imports projects by default.

Extractor is run in several steps:

Here is an example of how to run extractor from sbt REPL:

set SettingKey[Option[File]]("sbtStructureOutputFile") in Global := Some(file("structure.xml"))
set SettingKey[String]("sbtStructureOptions") in Global := "prettyPrint download"
apply -cp <path-to-extractor-jar> org.jetbrains.sbt.CreateTasks
*/*:dumpStructure

Settings

sbt-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:

Development notes

To publish artifacts locally bump version in build.sbt and run in sbt REPL:

publishAllLocal

Compatibility

sbt-structure is built and published for sbt 0.13.x and 1.x

sbt-structure-core is built and published for Scala 2.10, 2.11, 2.12, 2.13