Last active
March 18, 2022 01:10
-
-
Save mslinn/21684f1e5da630dfd734 to your computer and use it in GitHub Desktop.
Convert pom.xml to build.sbt
This file contains 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
import scala.xml._ | |
// To convert a Maven pom.xml to build.sbt: | |
// 1) Place this code into a file called PomToSbt.scala next to pom.xml | |
// 2) Type scala PomtoSbt.scala > build.sbt | |
// The dependencies from pom.xml will be extracted and place into a complete build.sbt file | |
// Because most pom.xml files only refernence non-Scala dependencies, I did not use %% | |
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"""" | |
} | |
s""" "$groupId" % "$artifactId" % "$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) |
@mslinn its not as simple as it's said here...
PomtoSbt.scala:1: error: object xml is not a member of package scala
Yup same here as @fancywriter mentioned.
Maybe something missing? (Version 2 vs 3? idk)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
It looks like classifier and artifactValName aren't being used