Created
February 12, 2019 21:04
-
-
Save malcolmgreaves/beee9179262ce4c2464d296d78a510e7 to your computer and use it in GitHub Desktop.
pom.xml-to-build.sbt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | |
} |
Use:
$ cd $DIR_WITH_POMXML_BUILD
$ scala PomToSbt.scala > build.sbt
$ sbt
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
My take on:
https://stackoverflow.com/questions/15430346/how-could-i-convert-a-pom-xml-to-sbt-dependencies