什么是最好的 Scala 构建系统? [英] What's the best Scala build system?

查看:19
本文介绍了什么是最好的 Scala 构建系统?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在这里看到了有关 IDE 的问题 -- 哪个是Scala 开发的最佳 IDE?什么是Scala 工具的当前状态?,但我对 IDE 的体验参差不齐.现在,我使用带有自动工作区刷新选项的 Eclipse IDE,并使用 KDE 4 的 Kate 作为我的文本编辑器.以下是我想解决的一些问题:

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:

  1. 使用我自己的编辑器 IDE 确实适合使用其组件的每个人.我更喜欢 Kate,但是刷新系统很烦人(它不使用 inotify,而是可能有 10 秒的轮询间隔).我不使用内置文本编辑器的原因是自动完成功能损坏导致 IDE 挂起可能 10 秒.
  2. 仅重建修改过的文件 Eclipse 构建系统已损坏.它不知道什么时候重建类.我发现自己几乎一半的时间用于项目->清理.更糟糕的是,即使它完成了我的项目的构建,几分钟后它也会弹出一些奇怪的错误(edit - 这些错误似乎是以前通过项目解决的问题 > clean,但后来又回来了......).最后,将首选项/如果项目包含错误则继续启动"设置为提示"似乎对 Scala 项目没有影响(即,即使有错误,它也始终启动).
  3. 构建定制 我可以使用夜间"版本,但我想修改和使用我自己的 Scala 构建,而不是内置到 IDE 插件中的编译器.将 [e.g.] -Xprint:jvm 传递给编译器(打印出降低的代码)也很不错.
  4. 快速编译 尽管 Eclipse 并不总是正确构建,但它看起来确实很活泼——甚至比 fsc 还要快.
  1. use my own editor IDEs 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.
  2. rebuild only modified files The Eclipse build system is broken. It doesn't know when to rebuild classes. I find myself almost half of 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).
  3. build customization I 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).
  4. fast compiling Though Eclipse doesn't always build right, it does seem snappy -- even more so than fsc.

我查看了 Ant 和 Maven,但还没有使用过(我还需要花时间解决 #3 和 #4).在我花时间让一个次优的构建系统工作之前,我想看看是否有人有其他建议.提前致谢!

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!

更新 - 我现在使用 Maven,将一个项目作为编译器插件传递给它.它似乎足够快;我不确定 Maven 使用什么样的 jar 缓存.Scala 2.8.0 的当前存储库可用 [link].原型非常酷,跨平台支持似乎非常好.但是,关于编译问题,我不确定 fsc 是否真的修复了,或者我的项目是否足够稳定(例如类名没有改变)——手动运行它并没有那么困扰我.如果您想查看示例,请随时浏览我正在使用的 pom.xml 文件 [github].

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

更新 2 - 从我看到的基准测试来看,Daniel Spiewak 是正确的,构建器比 Maven 快(而且,如果正在进行增量更改,Maven 的 10 秒延迟会令人讨厌),所以如果可以制作一个兼容的构建文件,那么它可能是值得的...

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 点和第 4 点极其难以使用当前的 scalac 进行管理.问题是 Scala 的编译器在构建文件方面有点笨拙.基本上,它会构建您提供给它的任何内容,而不管该文件是否真的需要构建.Scala 2.8.0 在这方面将有一些巨大的改进,但在那之前...... Eclipse SDT 实际上有一些非常精细(并且非常hackish)的代码用于进行更改检测和依赖项跟踪.总的来说,它做得不错,但正如你所看到的,有皱纹.Eclipse SDT 2.8.0 将依赖上述对 scalac 本身的改进.

Points 2 and 4 are extremely difficult 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.

因此,仅构建修改过的文件几乎是不可能的.除了 SDT,我所知道的唯一一个甚至尝试过这个的工具是 SBT(简单构建工具).它使用编译器插件在编译文件时跟踪文件并查询编译器本身计算的依赖关系图.在实践中,这比 recompile-the-world 方法产生了大约 50% 的改进.再一次,这是一个解决 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.

好消息是,即使不担心更改检测,仍然可以实现相当快的编译.FSC 使用 Eclipse SDT 用于实现快速增量编译的相同技术(哦,听起来很Charlie Eppes").简而言之,它非常活泼.

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.

就我个人而言,我使用 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).

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

如您所见,我非常坚信 Buildr 是目前最好的 Scala 构建工具.它的文档在 Scala 方面有点参差不齐,但这是因为一切都非常简单,以至于很难在不感到冗长的情况下进行记录.您可以随时查看 我的 GitHub 存储库 之一以获取示例.祝你好运!

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 repositories for examples. Good luck!

这篇关于什么是最好的 Scala 构建系统?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆