Skip to content

Instantly share code, notes, and snippets.

@cchantep
Last active December 19, 2015 10:19
Show Gist options
  • Save cchantep/5940062 to your computer and use it in GitHub Desktop.
Save cchantep/5940062 to your computer and use it in GitHub Desktop.
Loading Maven/POM settings from SBT
// Use Maven groupId as SBT organization
organization <<= (baseDirectory in Compile) { base ⇒
import scala.xml.XML
val pomFile = base / "pom.xml"
XML.loadFile(pomFile) \\ "project" \ "groupId" text
}
// Use Maven artifactId as SBT name
name <<= (baseDirectory in Compile) { base ⇒
import scala.xml.XML
val pomFile = base / "pom.xml"
XML.loadFile(pomFile) \\ "project" \ "artifactId" text
}
// Use Maven version as SBT one
version <<= (baseDirectory in Compile) { base ⇒
import scala.xml.XML
val pomFile = base / "pom.xml"
XML.loadFile(pomFile) \\ "project" \ "version" text
}
// Use Maven repositories as SBT resolvers, which is not managed by `externalPom()`
resolvers <<= (baseDirectory in Compile) { base ⇒
import scala.xml.XML
val pomFile = base / "pom.xml"
val pom = XML.loadFile(pomFile)
val repositories = pom \\ "project" \
"repositories" \ "repository"
repositories map { r ⇒
(r \ "name").text at (r \ "url").text
}
}
// Loads SBT dependencies from Maven POM
externalPom()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment