Skip to content

Instantly share code, notes, and snippets.

@metasim
Created January 8, 2016 20:14
Show Gist options
  • Select an option

  • Save metasim/31192966922376995ed9 to your computer and use it in GitHub Desktop.

Select an option

Save metasim/31192966922376995ed9 to your computer and use it in GitHub Desktop.
Attempt at a command to convert a pom.xml dependency specification into sbt syntax.
/** Utility command to convert in SBT a maven dependency fragment into SBT syntax. */
def Pom2SbtCommand = "pom2sbt"
def Pom2SbtHelp = " <pom.xml>"
import complete.DefaultParsers._
lazy val pomLibs2Sbt = Command(Pom2SbtCommand,
Help((Pom2SbtCommand, Pom2SbtHelp)))(_ ⇒ fileParser(new File("./"))) { (state, file) ⇒
import scala.xml.XML
val deps = XML.loadFile(file) \\ "dependency"
val sbtdeps = deps map ((dependency) ⇒ {
val coords = Seq("groupId", "artifactId", "version", "scope")
val coordParts = coords.map(coord ⇒ (dependency \ coord).text.trim).filter(_.nonEmpty)
coordParts.mkString("\"", "\" % \"", "\"")
})
println(s"Read ${sbtdeps.size} dependency entries from $file")
println(sbtdeps.mkString("\n"))
state
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment