Migrating from Maven to SBT

18,013

Solution 1

Converter is far too strong a term for this hack, but I wrote a script to take a block of <dependencies> and output SBT style deps: http://gist.github.com/388334

Solution 2

All the tips above had the issue for me that properties were not resolved, and as we make heavy use of the dependencyManagement from parent poms, I was hoping for something that actually could fully understand maven. I whipped together a simplistic scriptlet that outputs the dependencies from maven and just takes the top level items and then does a simple regex for the group, artifact, version, and scope (the artifact type is ignored)

mvn dependency:tree | grep "] +" | perl -pe 's/.*\s([\w\.\-]+):([\w\.\-]+):\w+:([\w\.\-]+):(\w+).*/libraryDependencies += "$1" % "$2" % "$3" % "$4"\n /' 

I piped this directly to project/build.sbt. The sample output is (remember to keep empty spaces between sbt lines)

libraryDependencies += "org.springframework" % "spring-core" % "3.1.0.RELEASE" % "compile"

libraryDependencies += "se.scalablesolutions.akka" % "akka-actor" % "1.3.1" % "compile"

libraryDependencies += "se.scalablesolutions.akka" % "akka-spring" % "1.3.1" % "compile"

Solution 3

Not a converter, but a step-by-step guide for moving a multimodule project from Maven to SBT can be found here.

Quite nice for understanding what actually happens and ensuring you have a fair amount of control over the proces..

Solution 4

I didn't manage to find an undocumented capability in SBT that allows to make such conversions (POM -> project definition), and have came up with writing a very simple script that creates SBT build file with repos/dependencies from POM.

In case you just need to convert Maven/XML dependencies into SBT/Scala, you can use this script provided by @retronym

Solution 5

I wrote mvn2sbt project for convertion java maven project to sbt project.

Share:
18,013

Related videos on Youtube

Vasil Remeniuk
Author by

Vasil Remeniuk

Enthusiastic and passionate leader with over a decade in product and engineering management, large-scale architecture, data and software development.

Updated on September 24, 2020

Comments

  • Vasil Remeniuk
    Vasil Remeniuk over 3 years

    As you know, SBT is compatible with Maven in some way -- SBT recognizes simple Maven POMs and can use dependencies and repositories specified in them. However, SBT wiki says that, if inline dependency is specified in SBT project definition, POM will be ignored (so using both in this case is impossible):

    Maven and Ivy configurations (pom.xml and ivy.xml) are ignored when inline dependency declarations are present.

    Does anyone know, if any kind of converter from Maven POM to SBT project definition exists (translating POM's XML into project definition Scala code)? I'm considering writing such script (that will help to migrate my old Scala/Maven projects to SBT), but want to know first, if this functionality already exists.

  • Vasil Remeniuk
    Vasil Remeniuk almost 14 years
    Nice hack! I was thinking about this kind of stuff (+ conversion of properties and repos).
  • dertoni
    dertoni almost 12 years
    the link seems to be dead, please use this one: github.com/rossabaker/maven-sbt
  • cevaris
    cevaris about 9 years
    Totally helpful, nice
  • bbarker
    bbarker over 7 years
    Very cool - a great way to get things up and (nearly) running!
  • Shon
    Shon over 3 years
    That link is dead :(