从 Maven 迁移到 SBT

发布于 2024-09-04 00:56:23 字数 446 浏览 5 评论 0原文

如您所知,SBT 在某种程度上与 Maven 兼容——SBT 识别简单的 Maven POM,并可以使用其中指定的依赖项和存储库。但是,SBT wiki 表示,如果在SBT项目定义,POM将被忽略(因此在这种情况下使用两者是不可能的):

Maven 和 Ivy 配置(pom.xml 和 ivy.xml) 在内联时被忽略 存在依赖声明。

有谁知道是否存在从 Maven POM 到 SBT 项目定义的任何类型的转换器(将 POM 的 XML 转换为项目定义 Scala 代码)?我正在考虑编写这样的脚本(这将有助于将我的旧 Scala/Maven 项目迁移到 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. 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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(8

揪着可爱 2024-09-11 00:56:23

对于这个 hack 来说,转换器这个术语太强大了,但我编写了一个脚本来获取 块并输出 SBT 样式 deps:http://gist.github.com/388334

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

探春 2024-09-11 00:56:23

上面的所有提示对我来说都有一个问题,即属性没有解决,并且当我们大量使用父 poms 的 dependencyManagement 时,我希望得到一些实际上可以完全理解 Maven 的东西。我整理了一个简单的 scriptlet,它从 Maven 输出依赖项,只获取顶级项目,然后为组、工件、版本和范围执行一个简单的正则表达式(工件类型被忽略)

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

我将其直接通过管道传输到项目/构建.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"

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"
九局 2024-09-11 00:56:23

不是转换器,而是将多模块项目从 Maven 移动到 SBT 的分步指南 此处

对于了解实际发生的情况并确保您对过程有相当程度的控制非常好。

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..

烛影斜 2024-09-11 00:56:23

我没有设法在 SBT 中找到允许进行此类转换的未记录功能(POM -> 项目定义),并且想出了编写 一个非常简单的脚本,用于创建 SBT 构建文件,其中包含来自 POM

如果您只需要将 Maven/XML 依赖项转换为 SBT/Scala,您可以使用提供的此脚本通过 @retronym

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

趁年轻赶紧闹 2024-09-11 00:56:23

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

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

挽心 2024-09-11 00:56:23

在 Git-Hub 上查看 CodaHale 的 Maven-SBT 项目。基本上,CodaHale 已经将 SBT 中的 IVY 替换为 Maven,因此与 POM 相关的任务应该更加兼容/灵活。

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 should be be more compatible/flexible.

甜妞爱困 2024-09-11 00:56:23

我编写了另一个 hack 来在 pom.xmlbuild.sbt 之间进行转换。它对于转换我感兴趣的大部分内容很有用。

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

I wrote yet another hack to convert between pom.xml and build.sbt. It's useful for converting the bulk of what I'm interested in.

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

﹏雨一样淡蓝的深情 2024-09-11 00:56:23

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

I just had the same problem and created a solution in javascript that you can access here:
http://www.maven-to-sbt.de/

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文