eclipse 什么是最好的 Scala 构建系统?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/972006/
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
What's the best Scala build system?
提问by gatoatigrado
I've seen questions about IDE's here -- Which is the best IDE for Scala development?and What is the current state of tooling for Scala?, but I've had mixed experiences with IDEs. Right now, I'm using the Eclipse IDE with the automatic workspace refresh option, and KDE 4's Kate as my text editor. Here are some of the problems I'd like to solve:
我在这里看到了有关 IDE 的问题——哪个是 Scala 开发的最佳 IDE?以及Scala 工具的当前状态是什么?,但我对 IDE 的体验参差不齐。现在,我使用带有自动工作区刷新选项的 Eclipse IDE,并使用 KDE 4 的 Kate 作为我的文本编辑器。以下是我想解决的一些问题:
- use my own editorIDEs are really geared at everyone using their components. I like Kate better, but the refresh system is very annoying (it doesn't use inotify, rather, maybe a 10s polling interval). The reason I don't use the built-in text editor is because broken auto-complete functionalities cause the IDE to hang for maybe 10s.
- rebuild only modified filesThe Eclipse build system is broken. It doesn't know when to rebuild classes. I find myself almost halfof the time going to project->clean. Worse, it seems even after it has finished building my project, a few minutes later it will pop up with some bizarre error (edit- these errors appear to be things that were previously solved with a project > clean, but then come back up...). Finally, setting "Preferences / Continue launch if project contains errors" to "prompt" seems to have no effect for Scala projects (i.e. it always launches even if there are errors).
- build customizationI can use the "nightly" release, but I'll want to modify and use my own Scala builds, not the compiler that's built into the IDE's plugin. It would also be nice to pass [e.g.]
-Xprint:jvm
to the compiler (to print out lowered code). - fast compilingThough Eclipse doesn't always build right, it does seem snappy -- even more so than
fsc
.
- 使用我自己的编辑器IDE 确实适合使用其组件的每个人。我更喜欢 Kate,但是刷新系统很烦人(它不使用 inotify,而是可能有 10 秒的轮询间隔)。我不使用内置文本编辑器的原因是因为损坏的自动完成功能会导致 IDE 挂起 10 秒。
- 仅重建修改过的文件Eclipse 构建系统已损坏。它不知道什么时候重建类。我发现自己几乎有一半的时间都在进行项目->清理。更糟糕的是,即使它完成了我的项目的构建,几分钟后它也会弹出一些奇怪的错误(编辑- 这些错误似乎是以前通过项目>清理解决的问题,但后来又回来了。 ...)。最后,将“首选项/如果项目包含错误则继续启动”设置为“提示”似乎对 Scala 项目没有影响(即,即使存在错误,它也始终启动)。
- 构建定制我可以使用“夜间”版本,但我想修改和使用我自己的 Scala 构建,而不是内置到 IDE 插件中的编译器。将 [eg] 传递
-Xprint:jvm
给编译器(打印出降低的代码)也很好。 - 快速编译虽然 Eclipse 并不总是正确构建,但它确实看起来很活泼——甚至比
fsc
.
I looked at Ant and Maven, though haven't employed either yet (I'll also need to spend time solving #3 and #4). I wanted to see if anyone has other suggestions before I spend time getting a suboptimal build system working. Thanks in advance!
我查看了 Ant 和 Maven,但还没有使用过(我还需要花时间解决 #3 和 #4)。在我花时间让一个次优的构建系统工作之前,我想看看是否有人有其他建议。提前致谢!
UPDATE- I'm now using Maven, passing a project as a compiler plugin to it. It seems fast enough; I'm not sure what kind of jar caching Maven does. A current repository for Scala 2.8.0 is available [link]. The archetypes are very cool, and cross-platform support seems very good. However, about compile issues, I'm not sure if fsc is actually fixed, or my project is stable enough (e.g. class names aren't changing) -- running it manually doesn't bother me as much. If you'd like to see an example, feel free to browse the pom.xml files I'm using [github].
更新- 我现在使用 Maven,将项目作为编译器插件传递给它。它似乎足够快;我不确定 Maven 做了什么样的 jar 缓存。Scala 2.8.0 的当前存储库可用 [链接]。原型非常酷,跨平台支持似乎非常好。然而,关于编译问题,我不确定 fsc 是否真的修复了,或者我的项目是否足够稳定(例如类名没有改变)——手动运行它并没有那么困扰我。如果您想查看示例,请随时浏览我正在使用的 pom.xml 文件 [ github]。
UPDATE 2- from benchmarks I've seen, Daniel Spiewak is right that buildr's faster than Maven (and, if one is doing incremental changes, Maven's 10 second latency gets annoying), so if one can craft a compatible build file, then it's probably worth it...
更新 2- 从我看到的基准测试来看,Daniel Spiewak 是正确的,构建器比 Maven 更快(并且,如果正在进行增量更改,Maven 的 10 秒延迟会很烦人),所以如果可以制作一个兼容的构建文件,那么它可能是值得...
采纳答案by Daniel Spiewak
Points 2 and 4 are extremelydifficult to manage with the current scalac. The problem is that Scala's compiler is a little dumb about building files. Basically, it will build whatever you feed it, regardless of whether or not that file really needs to be built. Scala 2.8.0 will have some tremendous improvements in this respect, but until then... Eclipse SDT actually has some very elaborate (and very hackish) code for doing change detection and dependency tracking. On the whole, it does a decent job, but as you have seen, there are wrinkles. Eclipse SDT 2.8.0 will rely on the aforementioned improvements to scalac itself.
使用当前的 scalac,第 2 点和第 4 点非常难以管理。问题是 Scala 的编译器在构建文件方面有点笨拙。基本上,无论您是否真的需要构建该文件,它都会构建您提供给它的任何内容。Scala 2.8.0 在这方面会有一些巨大的改进,但在那之前...... Eclipse SDT 实际上有一些非常精细(而且非常hackish)的代码来进行更改检测和依赖项跟踪。总的来说,它做得不错,但正如你所看到的,有皱纹。Eclipse SDT 2.8.0 将依赖上述对 scalac 本身的改进。
So, building only modified files is pretty much out of the question. Aside from SDT, the only tool I know of which even tries this is SBT (Simple Build Tool). It uses a compiler plugin to track files as they are compiled and query the dependency graph computed by the compiler itself. In practice, this yields about a 50% improvement over the recompile-the-world approach. Once again, this is a hack to get around deficiencies in pre-2.8.0 scalac.
因此,仅构建修改过的文件几乎是不可能的。除了 SDT,我所知道的唯一一个甚至尝试过这个的工具是 SBT(简单构建工具)。它使用编译器插件在编译文件时跟踪文件并查询由编译器本身计算的依赖关系图。在实践中,这比 recompile-the-world 方法产生了大约 50% 的改进。再一次,这是一个解决 2.8.0 之前的 scalac 缺陷的技巧。
The good news is that reasonably fast compilation is still achievable even without worrying about change detection. FSC uses the same technology (ooh, that sounded so "Charlie Eppes") that Eclipse SDT uses to implement fast incremental compilation. In short, it's pretty snappy.
好消息是,即使不担心更改检测,仍然可以实现相当快的编译。FSC 使用 Eclipse SDT 用于实现快速增量编译的相同技术(哦,听起来很“Charlie Eppes”)。简而言之,它非常活泼。
Personally, I use Apache Buildr. Its configuration is significantly cleaner than either Maven's or SBT's and its startup time is orders of magnitude less (when running under MRI). It integrates with FSC and attempts to do some basic change detection on its own (fairly primitive). It also has auto-magical support for the major Scala test frameworks (ScalaTest, ScalaCheck and Specs) as well as support for joint compilation with Java sources and IDE meta generation for IntelliJ and Eclipse. Oh, and it supports all of Maven's features (dependency resolution, etc) and then some. I'm even working on an extension which would allow interactive shell support integrated with JavaRebel and supporting several shell providers (Scala, JIRB, Clojure REPL, etc). It's not ready for the SVN yet, but I'll commit once it's ready (possibly in time for 1.3.5).
就个人而言,我使用Apache Buildr. 它的配置比 Maven 的或 SBT 的要干净得多,并且它的启动时间要少几个数量级(在 MRI 下运行时)。它与 FSC 集成并尝试自行进行一些基本的更改检测(相当原始)。它还为主要 Scala 测试框架(ScalaTest、ScalaCheck 和 Specs)提供自动神奇支持,并支持与 Java 源代码的联合编译以及 IntelliJ 和 Eclipse 的 IDE 元生成。哦,它支持 Maven 的所有功能(依赖项解析等),然后是一些。我什至正在开发一个扩展,它允许与 JavaRebel 集成的交互式 shell 支持并支持多个 shell 提供程序(Scala、JIRB、Clojure REPL 等)。它还没有为 SVN 做好准备,但是一旦它准备好我就会提交(可能及时到 1.3.5)。
As you can see, I'm very firmly of the opinion that Buildr is the best Scala build tool out there. Its documentation is a little spotty where Scala is concerned, but that's because everything is so straightforward that it's hard to document without feeling verbose. You can always check out one of my GitHub repositoriesfor examples. Good luck!
如您所见,我非常坚定地认为 Buildr 是目前最好的 Scala 构建工具。它的文档在 Scala 方面有点参差不齐,但这是因为一切都非常简单,以至于很难在不感到冗长的情况下进行记录。您可以随时查看我的 GitHub 存储库之一以获取示例。祝你好运!
回答by Brian Agnew
Have you looked at Intellij IDEA and its Scala integration? Intellij has a loyal (fanatical?) following amongst Java developers, so you may find this is appropriate for your needs.
你看过 Intellij IDEA 和它的Scala 集成吗?Intellij 在 Java 开发人员中拥有忠实(狂热?)的追随者,因此您可能会发现这适合您的需求。
回答by Y.H Wong
If you use Emacs, I think Ensimeis a pretty good IDE. I think at the time writing, Ensime is the only IDE that will give you fast and accurate autocompletion on both Scala and Java objects, including implicit conversions.
如果你使用 Emacs,我认为Ensime是一个非常好的 IDE。我认为在撰写本文时,Ensime 是唯一可以让您快速准确地自动完成 Scala 和 Java 对象(包括隐式转换)的 IDE。
There's code browsing support using Speedbar, code templates using the excellent Yasnippet, and code completion menu using Autocomplete. These are all very modern, actively maintained Emacs packages. There's also out of the box incremental building support for Maven and SBT.
有使用 Speedbar 的代码浏览支持,使用优秀的 Yasnippet 的代码模板,以及使用自动完成的代码完成菜单。这些都是非常现代的、积极维护的 Emacs 包。还有对 Maven 和 SBT 的开箱即用的增量构建支持。
There's a lot more in there such as interactive debugging, refactoring, and the Scala interpreter in an inferior process. All the things you want in a modern IDE for Scala is already there in Ensime. Highly recommended for Emacsens.
那里还有更多内容,例如交互式调试、重构和劣质进程中的 Scala 解释器。您在 Scala 的现代 IDE 中想要的所有东西都已经在 Ensime 中了。强烈推荐 Emacsens 使用。
回答by om-nom-nom
For the reasons of completeness, I have to say that there is also Pants-- the build tool that in use in Twitter (one of the early scala adopters)
出于完整性的考虑,我不得不说还有Pants——Twitter 中使用的构建工具(scala 的早期采用者之一)
The main difference it that it is intended not only for scala (and written in python, by the way) and is modeled after google build system.
主要区别在于它不仅适用于 scala(顺便说一句,用 python 编写),而且是在google build system之后建模的。
It's not so bloated as sbt, so for the freshmans it's much simplier, but I've never heard about Pants usage outside of twitter and foursquare.
它不像 sbt 那样臃肿,所以对于新生来说,它要简单得多,但我从未听说过除了 twitter 和foursquare 之外的Pants 用法。
If you scared of SBT, maybe another no-so-popular build tool, ABT, could be an alternativefor you?
如果您害怕 SBT,也许另一个不那么受欢迎的构建工具ABT可以成为您的替代品?
回答by dberesford
Am also quite frustrated with the scala plugin on Eclipse and I can add a few more problems to the list:
我也对 Eclipse 上的 scala 插件感到非常沮丧,我可以在列表中添加更多问题:
- auto-complete only works some of the time
- the debugger doesn't work properly (especially when trying to debug scala xml)
- the debugger forgets breakpoints
- 'go to definition' doesn't work more often than not.
- 自动完成仅在某些时候有效
- 调试器无法正常工作(尤其是在尝试调试 scala xml 时)
- 调试器忘记断点
- “转到定义”通常不起作用。
I'm glad to hear that Buildr sounds like a better alternative (on the build front anyhow), I'll give that a try - thanks!
我很高兴听到 Buildr 听起来是一个更好的选择(无论如何在构建方面),我会尝试一下 - 谢谢!
回答by dberesford
I went down the same road, and here is where I am at: - After some initial investigation, I dropped Kate. I love to use it for most things, but when it came to things like defining tab completions, I found it sorely lacking. I would recommend that you look into gedit instead, which is much more robust for Scala development - With gedit as my editor, I use SBT and have found it to be a great build tool. I can put it into a 'test' mode where when any code changes it recompiles the relevant files and runs my test suite. This has been an extremely effective way to work.
我走了同样的路,这里是我所在的地方: - 经过一些初步调查,我放弃了凯特。我喜欢在大多数事情上使用它,但是当涉及到定义制表符完成等事情时,我发现它非常缺乏。我建议您改用 gedit,它对于 Scala 开发来说更加健壮 - 使用 gedit 作为我的编辑器,我使用 SBT 并发现它是一个很棒的构建工具。我可以将它置于“测试”模式,当任何代码更改时,它会重新编译相关文件并运行我的测试套件。这是一种非常有效的工作方式。
I have not taken a look at Buildr yet. I would like to say that I will, but honestly with SBT at my disposal I don't really have a compelling need to look at another build tool.
我还没有看过 Builder。我想说我会,但老实说,我可以使用 SBT,我真的没有迫切需要查看其他构建工具。
回答by Roland
If you want to use Eclipse, but build the project using sbt, and still be able to debug, take a look at this post here:
如果您想使用 Eclipse,但使用 sbt 构建项目,并且仍然能够调试,请查看这里的这篇文章:
zikaprog.wordpress.com/2010/04/19/scala-eclipse-sbt-and-debugging/
zikaprog.wordpress.com/2010/04/19/scala-eclipse-sbt-and-debugging/
It also can be applied to builders other than sbt.
它也可以应用于 sbt 以外的构建器。
回答by sourcedelica
The latest version of the Maven Scala plugin supports Zinc/Nailgun for faster start times and faster incremental builds. See Zinc and Incremental Compilation.
最新版本的 Maven Scala 插件支持 Zinc/Nailgun 以实现更快的启动时间和更快的增量构建。请参阅Zinc 和增量编译。