Skip to content

Instantly share code, notes, and snippets.

@schmmd
Last active December 14, 2015 07:29
Show Gist options
  • Save schmmd/5050790 to your computer and use it in GitHub Desktop.
Save schmmd/5050790 to your computer and use it in GitHub Desktop.
Create an sbt file from a pom file.
import scala.xml._
val scalaVersion = args.headOption
def quote(s: String) = "\"" + s + "\""
val xml = XML.loadString(scala.io.Source.stdin.getLines.mkString("\n"))
val name = (xml \ "artifactId").text
val version = (xml \ "version").text
case class Repository(name: String, url: String) {
def sbtString = quote(name) + " at " + quote(url)
}
val repositories = (xml \\ "repository").map { repo =>
Repository((repo \ "id").text, (repo \ "url").text)
}
case class Dependency(groupId: String, artifactId: String, version: String) {
def sbtString = scalaVersion match {
case Some(scalaVersion) if (artifactId contains ("_" + scalaVersion)) => quote(groupId) + " %% " + quote(artifactId.take(artifactId.indexOf("_" + scalaVersion))) + " % " + quote(version)
case _ => quote(groupId) + " % " + quote(artifactId) + " % " + quote(version)
}
}
val dependencies = (xml \\ "dependency").map { dep =>
Dependency((dep \ "groupId").text, (dep \ "artifactId").text, (dep \ "version").text)
}
(Seq(
"name" -> name,
"version" -> version
) ++ scalaVersion.map("scalaVersion" -> _)).foreach { case (name, value) => println(name + " := " + quote(value)); println() }
println("resolvers ++= " + repositories.map(_.sbtString).mkString("Seq(", ",\n ", ")"));
println()
println("libraryDependencies ++= " + dependencies.map(_.sbtString).mkString("Seq(", ",\n ", ")"));
println()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment