How could I convert a pom xml to sbt dependencies?
pom.xml, sbt
Solution
This scala script, which runs from command line, takes care of that, converting the pom.xml file to sbt dependencies printed on screen. Then you only need to copy paste once for each pom.xml file.
Note: the pom.xml must be in the same folder as the script. Then from command line you execute: `scala scriptname.scala`
import scala.xml._
(XML.load("pom.xml") \\ "dependencies") \ "dependency" foreach ((dependency: Node) => {
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("[-\\.]", "_")
print("val %s = \"%s\" %% \"%s\" %% \"%s\"".format(artifactValName, groupId, artifactId, version))
scope match {
case "" => print("\n")
case _ => print(" %% \"%s\"\n".format(scope))
}
None
});
Problem
I have some projects that have all the dependencies stored inside pom.xml files. How could I retrieve the dependencies from inside so I could easily place them to a project that uses sbt? Copy pasting all of them is just time consuming..