scala 比较 sbt 和 Gradle
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11061938/
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
comparing sbt and Gradle
提问by Hans Westerbeek
I am diving into Scala and noticed sbt. I have been quite happy with Gradle in java/groovy projects, and I know there's a scala plugin for Gradle.
我正在潜入 Scala 并注意到 sbt。我对 java/groovy 项目中的 Gradle 非常满意,我知道 Gradle 有一个 Scala 插件。
What could be good reasons to favour sbt over Gradle in a Scala project?
在 Scala 项目中,有什么理由支持 sbt 而不是 Gradle?
采纳答案by VonC
Note that one key difference between SBT and Gradle is its dependency management:
请注意,SBT 和 Gradle 之间的一个主要区别在于其依赖项管理:
- SBT: Ivy, with a a revision which can be given as a fixed one (1.5.2, for instance) or as latest (or dynamic) one.
See "Ivy Dependency"
That means the "-SNAPSHOT" mechanism support can be problematic, even though Mark Harrahdetails in this thread:
- SBT:Ivy,带有一个修订版,可以作为固定版本(例如 1.5.2)或最新(或动态)版本给出。
请参阅“常春藤依赖”
这意味着“-SNAPSHOT”机制支持可能有问题,即使此线程中的Mark Harrah详细信息:
It is true the cache can get confused, but it is not true that Ivy doesn't understand resolving snapshots. Eugene explained this point in another thread, perhaps on the admin list. There is an issue with sbt's auto-update that was addressed in 0.12.
What Ivy does not support, as far as I know, is publishing snapshots in the manner Maven does. I believe I have stated this elsewhere, but if anyone wants to improve the situation, my opinion is that effort is best spent working with the Gradle team to reuse their dependency management code.
缓存确实会被混淆,但 Ivy 不理解解析快照并不是真的。Eugene 在另一个线程中解释了这一点,可能在管理员列表中。sbt 的自动更新存在一个问题,已在 0.12 中解决。
据我所知,Ivy 不支持以 Maven 的方式发布快照。我相信我已经在别处说明了这一点,但如果有人想改善这种情况,我的意见是最好与 Gradle 团队合作以重用他们的依赖项管理代码。
- Gradle: This threadmentions (Peter Niederwieser):
Just to let you know, problems with Ivy and Maven snapshot dependencies were one of the reasons why Gradle eventually replaced Ivy with its own dependency management code. It was a big task, but brought us a lot of goodness.
只是让您知道,Ivy 和 Maven 快照依赖项的问题是 Gradle 最终用自己的依赖管理代码替换 Ivy 的原因之一。这是一项艰巨的任务,但给我们带来了很多好处。
This tweetmentions that the all situation could evolve in the future:
这条推文提到所有情况都可能在未来发展:
Mark said in the past that he was interested in using Gradle instead of Ivy for SBT.
Mark 过去曾说过,他有兴趣在 SBT 中使用 Gradle 而不是 Ivy。
(both tools can learn from each other)
(两个工具可以互相学习)
回答by paradigmatic
For me the key features of SBT are:
对我来说,SBT 的主要特点是:
- Fast compilation (faster than
fsc). - Continuous compilation/testing: the command
~testwill recompile and test you project everytime you save a modification. - Cross-compilation and cross-publishing, across several scala versions.
- Automatically retrieving dependencies with the correct scala version compatibility.
- 快速编译(比 快
fsc)。 - 持续编译/测试:
~test每次保存修改时,该命令都会重新编译和测试您的项目。 - 跨多个 Scala 版本的交叉编译和交叉发布。
- 自动检索具有正确 Scala 版本兼容性的依赖项。
The downsides are:
缺点是:
- A hieroglyphic syntax that tends to discourage new users (especially if they come from Java)
- No easy way to define a "task": if you need a special build procedure, you will need to either find a plugin, or write a plugin yourself.
- 一种倾向于阻止新用户的象形文字语法(特别是如果他们来自 Java)
- 定义“任务”没有简单的方法:如果您需要特殊的构建过程,您将需要找到一个插件,或者自己编写一个插件。
回答by Jens Schauder
sbt is a Scala DSL and for it Scala is a first class citizen, so in principal it seems to be a good fit.
sbt 是 Scala DSL,因此 Scala 是一等公民,因此原则上它似乎很合适。
But sbt suffers from major incompatible changes between versions, which makes it hard to find the correct working plugin for a task and get it to work.
但是 sbt 在版本之间存在重大的不兼容更改,这使得很难为任务找到正确的工作插件并使其工作。
I personally gave up on sbt, since it was causing more problems than it solved. I actually switched to gradle.
我个人放弃了 sbt,因为它造成的问题多于解决的问题。我实际上切换到了 gradle。
Go figure.
去搞清楚。
回答by eugenevd
I'm fairly new to gradle, and very new to sbt - what I really like about sbt so far is the interactive console. It allows me to use commands like 'inspect' to get a better idea of what's going on. AFAIK gradle does not provide something like this atm.
我对 gradle 还很陌生,对 sbt 也很陌生——到目前为止,我真正喜欢 sbt 的是交互式控制台。它允许我使用诸如“检查”之类的命令来更好地了解正在发生的事情。AFAIK gradle 不提供类似这种 atm 的东西。
回答by Saby
Sbt and gradle, both are based on statically typed languages....but sbt has few advantages:
Sbt 和 gradle,两者都基于静态类型语言......但 sbt 几乎没有优势:
- better plugin support, specially autoplugins
- task creation and dependency management between tasks
- sbt specially suits scala projects in the sense that it supports incremental builds and most of the sbt itself is written in scala and sbt build definitions is written in scala
- sbt has interative shell support with many useful built-in tasks
- sbt default lifecycle is pretty useful and can get novice started with pretty less effort
- 更好的插件支持,特别是自动插件
- 任务创建和任务之间的依赖管理
- sbt 特别适合 scala 项目,因为它支持增量构建,而且大部分 sbt 本身都是用 Scala 编写的,而 sbt 构建定义是用 Scala 编写的
- sbt 具有交互式 shell 支持和许多有用的内置任务
- sbt 默认生命周期非常有用,可以让新手轻松入门

