简体   繁体   English

从 Maven 迁移到 SBT

[英]Migrating from Maven to SBT

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.如您所知,SBT 在某些方面与 Maven 兼容——SBT 识别简单的 Maven POM 并且可以使用其中指定的依赖项和存储库。 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):但是, 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)?有谁知道,是否存在从 Maven POM 到 SBT 项目定义的任何类型的转换器(将 POM 的 XML 转换为项目定义 Scala 代码)? 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.我正在考虑编写这样的脚本(这将有助于将我的旧 Scala/Maven 项目迁移到 SBT),但首先想知道这个功能是否已经存在。

转换器对于这个 hack 来说太强大了,但我写了一个脚本来获取<dependencies>块并输出 SBT 风格的 deps: http : //gist.github.com/388334

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.上面的所有提示对我来说都有一个问题,即属性没有解决,并且当我们大量使用来自父 poms 的依赖管理时,我希望有一些实际上可以完全理解 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)我制作了一个简单的 scriptlet,它从 maven 输出依赖项,只获取顶级项目,然后为组、工件、版本和范围做一个简单的正则表达式(工件类型被忽略)

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.我直接将它传送到 project/build.sbt。 The sample output is (remember to keep empty spaces between sbt lines)示例输出是(记住在 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"

Not a converter, but a step-by-step guide for moving a multimodule project from Maven to SBT can be found here .不是转换器,而是可以在此处找到将多模块项目从 Maven 迁移到 SBT 的分步指南。

Quite nice for understanding what actually happens and ensuring you have a fair amount of control over the proces..非常适合了解实际发生的情况并确保您对过程有相当程度的控制。

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 .我没有设法在 SBT 中找到允许进行此类转换(POM -> 项目定义)的未记录功能,并且想出了编写一个非常简单的脚本,该脚本创建带有来自POM 的repos/dependencies 的SBT 构建文件

In case you just need to convert Maven/XML dependencies into SBT/Scala, you can use this script provided by @retronym如果您只需要将 Maven/XML 依赖项转换为 SBT/Scala,您可以使用@retronym提供的这个脚本

我编写了mvn2sbt项目,用于将 java maven 项目转换为 sbt 项目。

Take a look a CodaHale's Maven-SBT project over at Git-Hub.在 Git-Hub 上查看 CodaHale 的 Maven-SBT 项目。 Basically, CodaHale has swapped out IVY from SBT and replaced it with Maven, so POM related tasks should be be more compatible/flexible.基本上,CodaHale 已经将 IVY 从 SBT 换成了 Maven,因此 POM 相关的任务应该更加兼容/灵活。

I wrote yet another hack to convert between pom.xml and build.sbt .我写了另一个 hack 在pom.xmlbuild.sbt之间转换。 It's useful for converting the bulk of what I'm interested in.这对于转换我感兴趣的大部分内容很有用。

https://gist.github.com/schmmd/5050790 https://gist.github.com/schmmd/5050790

我刚刚遇到了同样的问题,并在 javascript 中创建了一个解决方案,您可以在这里访问: http : //www.maven-to-sbt.de/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM