Skip to content

Instantly share code, notes, and snippets.

@OleTraveler
Forked from retronym/mvn2sbt.scala
Created June 23, 2011 16:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save OleTraveler/1042926 to your computer and use it in GitHub Desktop.
Save OleTraveler/1042926 to your computer and use it in GitHub Desktop.
mvn2sbt: updated to convert to 0.10.0 build.sbt file
val xml = <dependencies>
<dependency>
<groupId>javax.persistence</groupId>
<artifactId>persistence-api</artifactId>
<version>1.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>net.sf.oval</groupId>
<artifactId>oval</artifactId>
<version>1.70</version>
</dependency>
</dependencies>
val data: Seq[(String, String, String, Option[String])] = (xml \ "dependency") map { d =>
val groupId = d \ "groupId" text
val artifactId = d \ "artifactId" text
val versionNum = d \ "version" text
val scope = d \ "scope" text
(groupId, artifactId, versionNum, if (scope.size > 0) Some(scope) else None)
}
val CrossBuildArtifact = """([\w-]+)_\$SCALA_VERSION\$""".r
def dep(a: String, g: String, v: String, s: Option[String], cross: Boolean) = {
val sep = if (cross) "%%" else "%"
val ident = a.split("-").map(_.capitalize).mkString
val base = """ "%s" %s "%s" %% "%s" """ format (g, sep, a, v)
base + s.map(" % \"" + _ + "\"").getOrElse("")
}
val m = data map {
case (g, CrossBuildArtifact(a), v, s) => dep(a, g, v, s, true)
case (g, a, v, s) => dep(a, g, v, s, false)
} mkString(",\n")
println(m)
"javax.persistence" % "persistence-api" % "1.0" % "provided",
"net.sf.oval" % "oval" % "1.70"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment