Convert your pom xml to build sbt
Aren't you at your limits dealing with XML? If so why still bother using a build tool that still uses an outdated format like the XML? Why use Maven when you can be friends with sbt? Here is a small script that helps you to convert your pom.xml to a build.sbt. The generated build.sbt is rusty, and you need to adapt it after it is converted.
1#!/bin/sh
2exec /opt/softwares/scala-2.12.2/bin/scala "$0" "$@"
3!#
4
5/***
6scalaVersion := "2.12.2"
7
8libraryDependencies ++= Seq(
9 "org.scala-lang.modules" %% "scala-xml" % "2.0.0"
10)
11*/
12
13import scala.xml._
14
15val lines = (XML.load("pom.xml") \\ "dependencies") \ "dependency" map { dependency =>
16 val groupId = (dependency \ "groupId").text
17 val artifactId = (dependency \ "artifactId").text
18 val version = (dependency \ "version").text
19 val scope = (dependency \ "scope").text
20 val classifier = (dependency \ "classifier").text
21 val artifactValName: String = artifactId.replaceAll("[-\\.]", "_")
22
23 val scope2 = scope match {
24 case "" => ""
25 case _ => s""" % "$scope""""
26 }
27
28 s""" "$groupId" % "$artifactId" % "$version"$scope2"""
29}
30
31val buildSbt = io.Source.fromURL("https://gist.githubusercontent.com/joesan/59d36606f0529af148000d54202eb370/raw/f854aa443686051637068667401d1e9a412ad192/build.sbt").mkString
32val libText = "libraryDependencies ++= Seq("
33val buildSbt2 = buildSbt.replace(libText, libText + lines.mkString("\n", ",\n", ""))
Save this file as convert.sh in the same location where your pom.xml is located
Calling it is pretty simple!
1./convert.sh > build.sbt
One thing that is worth mentioning that XML support for Scala was dropped with Scala versions 2.13 and up, so to be able to run this script, you need to have Scala 2.12 installed. I have Scala 2.12.2 in my path, and you can see that in this line here:
1exec /opt/softwares/scala-2.12.2/bin/scala "$0" "$@"
For now ignore the two parameters, "$0" "$@"
as they are there if you need to pass parameters from outside. So there you
have it. Instant conversion of pom.xml to build.sbt. If you need to pass in additional parameters, use these placeholders to
inject them into the Scala code.