Piotr Gabryanczyk’s Blog

Java, Refactoring, AOP, Spring, DDD, TDD, etc.

  • Blogroll

    • I have joined Anti-IF Campaign

Converting Maven pom.xml to SBT

Posted by Piotr Gabryanczyk on November 14, 2010

Add this task to your project class.
Run reload, then pom2sbt.
Copy the output to the project file and enjoy!

lazy val pom2sbt = task {
    val deps = XML.load("pom.xml") \\ "dependencies"
    deps \"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))
    } )

One Response to “Converting Maven pom.xml to SBT”

  1. Hmm it appears like your blog ate my first comment (it was super long)
    so I guess I’ll just sum it up what I had written and say, I’m thoroughly
    enjoying your blog. I as well am an aspiring blog writer
    but I’m still new to everything. Do you have any helpful hints for novice blog writers? I’d certainly appreciate it.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: