Skip to content

Instantly share code, notes, and snippets.

@malcolmgreaves
Created February 12, 2019 21:04
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save malcolmgreaves/beee9179262ce4c2464d296d78a510e7 to your computer and use it in GitHub Desktop.
Save malcolmgreaves/beee9179262ce4c2464d296d78a510e7 to your computer and use it in GitHub Desktop.
pom.xml-to-build.sbt
object PomToSbt extends App {
import scala.xml._
val lines = (XML.load("pom.xml") \\ "dependencies") \ "dependency" map { dependency =>
val groupId = (dependency \ "groupId").text
val artifactId = (dependency \ "artifactId").text
val version = (dependency \ "version").text
val scope = (dependency \ "scope").text
val classifier = (dependency \ "classifier").text
val artifactValName: String = artifactId.replaceAll("[-\\.]", "_")
val scope2 = scope match {
case "" => ""
case _ => s""" % "$scope""""
}
val artifactStr =
if (artifactId.contains("_2.") || artifactId.contains("_${") || artifactId.contains("scala-library"))
s"""% "$artifactId""""
else
s"""%% "$artifactId""""
s""" "$groupId" $artifactStr % "$version"$scope2"""
}
val buildSbt = io.Source.fromURL("https://raw.githubusercontent.com/mslinn/sbtTemplate/master/build.sbt").mkString
val libText = "libraryDependencies ++= Seq("
val buildSbt2 = buildSbt.replace(libText, libText + lines.mkString("\n", ",\n", ""))
println(buildSbt2)
}
@malcolmgreaves
Copy link
Author

malcolmgreaves commented Feb 12, 2019

Use:

$ cd $DIR_WITH_POMXML_BUILD
$ scala PomToSbt.scala > build.sbt
$ sbt

@malcolmgreaves
Copy link
Author

FYI this script needs some fixing-up -- the template has some extraneous stuff, is kind of out-of-order, and forgets to add some , and other necessary symbols. However, it get most of the way there! (And the downloaded template has some good documentation on sbt config stuff).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment