Skip to content

Instantly share code, notes, and snippets.

@SureshChaganti
Forked from dportabella/PomDependenciesToSbt
Created July 27, 2016 20:40
Show Gist options
  • Select an option

  • Save SureshChaganti/78af1e4d6b484c864e5e434884714ccc to your computer and use it in GitHub Desktop.

Select an option

Save SureshChaganti/78af1e4d6b484c864e5e434884714ccc to your computer and use it in GitHub Desktop.

Revisions

  1. @dportabella dportabella revised this gist Jul 7, 2016. No changes.
  2. @dportabella dportabella revised this gist Jul 7, 2016. No changes.
  3. @dportabella dportabella revised this gist May 31, 2016. No changes.
  4. @dportabella dportabella revised this gist May 31, 2016. 1 changed file with 9 additions and 2 deletions.
    11 changes: 9 additions & 2 deletions PomDependenciesToSbt
    Original file line number Diff line number Diff line change
    @@ -24,8 +24,15 @@ def main(pomPath: String, path: Path = cwd) = {
    case _ => s""" % "$scope""""
    }

    s""" "$groupId" % "$artifactId" % "$version"$scope2"""
    val exclusions = (dependency \ "exclusions" \ "exclusion" map { exclusion =>
    val groupId = (exclusion \ "groupId").text
    val artifactId = (exclusion \ "artifactId").text

    s"""\n exclude("$groupId", "$artifactId")"""
    }).mkString

    s""" "$groupId" % "$artifactId" % "$version"$scope2$exclusions"""
    }

    lines.foreach(println)
    println(lines.mkString("", ",\n", "\n"))
    }
  5. @dportabella dportabella created this gist May 30, 2016.
    31 changes: 31 additions & 0 deletions PomDependenciesToSbt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,31 @@
    #!/usr/bin/env amm

    // This script converts Maven dependencies from a pom.xml to sbt dependencies.
    // It is based on the answers of George Pligor and Mike Slinn on http://stackoverflow.com/questions/15430346/
    // - install https://github.com/lihaoyi/Ammonite
    // - make this script executable: chmod +x PomDependenciesToSbt
    // - run it with from your shell (e.g bash):
    // $ ./PomDependenciesToSbt /path/to/pom.xml

    import scala.xml._
    import ammonite.ops._

    def main(pomPath: String, path: Path = cwd) = {
    val lines = (XML.load(pomPath) \\ "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"""
    }

    lines.foreach(println)
    }