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..
For that, you need to run a simple command cmd at the same location where pom. xml is present. The command is mvn dependency:analyze, once you run this command you will see those dependencies which are not correct. That's how you can add and manage dependencies in pom.
POM is an acronym for Project Object Model. The pom. xml file contains information of project and configuration information for the maven to build the project such as dependencies, build directory, source directory, test source directory, plugin, goals etc. Maven reads the pom.
All new SBT versions (after 0.7. x ) by default put the downloaded JARS into the . ivy2 directory in your home directory. If you are using Linux, this is usually /home/<username>/.
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
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With