scala 从 Maven 迁移到 SBT
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2972195/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Migrating from Maven to SBT
提问by Vasil Remeniuk
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 wikisays that, if inline dependency is specified in SBT project definition, POM will be ignored (so using both in this case is impossible):
如您所知,SBT 在某些方面与 Maven 兼容——SBT 识别简单的 Maven POM 并且可以使用其中指定的依赖项和存储库。但是,SBT wiki说,如果在 SBT 项目定义中指定了内联依赖项,POM 将被忽略(因此在这种情况下使用两者是不可能的):
Maven and Ivy configurations (pom.xml and ivy.xml) are ignored when inline dependency declarations are present.
当存在内联依赖声明时,Maven 和 Ivy 配置(pom.xml 和 ivy.xml)将被忽略。
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.
有谁知道,是否存在从 Maven POM 到 SBT 项目定义的任何类型的转换器(将 POM 的 XML 转换为项目定义 Scala 代码)?我正在考虑编写这样的脚本(这将有助于将我的旧 Scala/Maven 项目迁移到 SBT),但首先想知道这个功能是否已经存在。
采纳答案by retronym
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
转换器对于这个 hack 来说太强大了,但我写了一个脚本来获取<dependencies>和输出 SBT 风格的 deps:http: //gist.github.com/388334
回答by JoshMahowald
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)
上面的所有提示对我来说都有一个问题,即属性没有得到解决,并且当我们大量使用来自父 poms 的依赖管理时,我希望有一些实际上可以完全理解 maven 的东西。我制作了一个简单的 scriptlet,它从 maven 输出依赖项,只获取顶级项目,然后为组、工件、版本和范围执行简单的正则表达式(工件类型被忽略)
mvn dependency:tree | grep "] +" | perl -pe 's/.*\s([\w\.\-]+):([\w\.\-]+):\w+:([\w\.\-]+):(\w+).*/libraryDependencies += "" % "" % "" % ""\n /'
I piped this directly to project/build.sbt. The sample output is (remember to keep empty spaces between sbt lines)
我直接将它传送到 project/build.sbt。示例输出是(记住在 sbt 行之间保留空格)
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"
回答by Vasil Remeniuk
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 scriptthat creates SBT build filewith repos/dependencies from POM.
我没有设法在 SBT 中找到允许进行此类转换(POM -> 项目定义)的未记录功能,并且想出了编写一个非常简单的脚本,该脚本创建带有来自POM 的存储库/依赖项的SBT 构建文件。
In case you just need to convert Maven/XML dependencies into SBT/Scala, you can use this scriptprovided by @retronym
回答by Andrzej Jozwik
回答by Didia
回答by Big Rich
Take a look a CodaHale's Maven-SBT project over at Git-Hub. Basically, CodaHale has swapped out IVY from SBT and replaced it with Maven, so POM related tasks shouldbe be more compatible/flexible.
在 Git-Hub 上查看 CodaHale 的 Maven-SBT 项目。基本上,CodaHale 已经将 IVY 从 SBT 换成了 Maven,因此 POM 相关的任务应该更加兼容/灵活。
回答by StaroX
I just had the same problem and created a solution in javascript that you can access here: http://www.maven-to-sbt.de/
我刚刚遇到了同样的问题,并在 javascript 中创建了一个解决方案,您可以在这里访问:http: //www.maven-to-sbt.de/
回答by schmmd
I wrote yet another hack to convert between pom.xmland build.sbt. It's useful for converting the bulk of what I'm interested in.
我写了另一个 hack 来在pom.xml和之间转换build.sbt。这对于转换我感兴趣的大部分内容很有用。

