如何在不依赖 IDE 的情况下构建/测试 Scala?
我现在已经开始学习 Scala 并且非常享受它;我希望用它来启动未来的项目,而不是 Java。我不太喜欢的是(相对)较差的 IDE 支持。我发现带有 Scala 插件(包括夜间构建)的 IDEA 和 Eclipse 都有点不可靠或难以使用 - 我想要一些我可以始终依赖的东西。例如,昨天我根本无法重新安装 eclipse+plugin 来运行我的测试,甚至无法打开编辑器窗口!
我正在考虑在 Eclipse/IDEA 之间切换,具体取决于哪一个最适合手头的任务,更重要的是减少我对 IDE 构建和运行测试 (ScalaTest) 的依赖。这对我来说意义重大,因为我是在 Eclipse 中使用 Java 长大的。让 Eclipse SVN 使用 GIT 最初是一件大事。鉴于我只有时间学习一种工具,应该是Ant,Maven,buildr,sbt,....?其他人如何工作?
I'm well into learning Scala now and enjoying it very much; I hope to start future projects in it, rather than Java. What I'm enjoying less is the (relatively) poor IDE support. I've found both IDEA and Eclipse with the Scala Plugin (including nightly builds) to be a bit unreliable or difficult to use - I want something I can always depend on. E.g. yesterday I couldn't get a fresh install of eclipse+plugin to run my tests at all, or even open an editor window!
I'm considering hopping between Eclipse/IDEA depending on which suits the task at hand best and more importantly cutting my dependence on the IDE for building and running tests (ScalaTest). This is non-trivial for me since I've grown up on Java in Eclipse; leaving Eclipse SVN to use GIT was initially a big deal. Given that I only have time to learn one tool, should it be Ant, Maven, buildr, sbt,.... ? How do other people work?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
我已经将 Maven 和 sbt 与 Scala 结合使用,发现它们都非常易于使用。
然而,sbt 感觉更接近 Scala,因为它的构建文件是用 Scala 本身编写的(而不是 Maven 中的 XML),并且 sbt 具有构建 REPL,具有持续编译和测试等功能。
所以我建议您使用 sbt简单的 Scala 项目。
但如果你想创建标准的 Java 项目,如 WAR、EJB 等,我觉得 Maven 对它们有更好的支持。
此外,Maven 还拥有一个庞大的插件生态系统,使您能够执行几乎所有操作,包括代码覆盖率、报告、代码标准检查、文档生成等等。
I have used both Maven and sbt with Scala and found both of them pretty easy to use.
However, sbt feel much more closer to Scala as its build files are written in Scala itself (as opposed to XML in Maven) and sbt feature a build REPL, has continuous compilation and testing etc.
So I would advise you to use sbt for a simple Scala project.
But in case you want to create standard Java projects like WAR, EJB etc, I feel like Maven has a better support for them.
Also Maven has an enormous plugin ecosystem which enables you to do virtually everything, code coverage, reporting, code standard checking, documentation generation, and a lot more.
我会结合使用 SBT 和 IDEA。虽然我没有尝试过,但我知道有一些支持 SBT 和 IDEA 的集成。
不管怎样,SBT 是满足所有 Scala 构建和测试需求的良好基础。
I'd use SBT with IDEA. Though I haven't tried it, I know there's some support for integration of SBT and IDEA.
Anyway, SBT is a great basis for all Scala building&testing needs.
编辑:Uuuups。对不起。实际上我误读了你的问题,只对 IDE 发表了评论。当谈到构建项目时,我使用 make ;) 因为它很好地集成到了 Vim 中,
而我不想在没有 IDE 的情况下做任何 Java 项目,我目前正在做一个相当大的项目 Vim。我知道这是一种相当“石器时代的方法”,但效果很好。
一方面,我厌倦了所有 IDE 的错误/缓慢/缺乏 Scala 支持。我尝试了 Scala、netbeans 和 IDEA,发现使用它们(在 Scala 中)相当痛苦。
另一方面,Scala 有一些属性可以在使用简单编辑器时提供帮助:您可以在一个文件中包含更多类,因此我通常在一个文件中定义整个包,该文件也不会变得太大,因为 Scala 类通常非常大(甚至极其)小。所以我通常一次只打开两个或三个文件,因此不需要包/文件管理。
我无法让按语言标签进行代码折叠工作,但如果您坚持 Scala 的缩进约定,按缩进折叠就可以正常工作。
不起作用的一件事是自动完成。但话又说回来,这让我编写了更松散耦合的对象;)
EDIT: Uuuups. Sorry. Actually I misread your question and only commented on IDEs. When it comes to building the project I use make ;) because it is well integrated into Vim
while I wouldn't want to do ANY Java Project without IDE, I'm currently doing a fairly large project just in Vim. I know that's a quite a "stone-age approach" but it works just fine.
On one hand I was fed up by the buggy/slow/lacking Scala support of all IDEs. I tried Scala, netbeans and IDEA and found working with them (in Scala) rather painful.
On the other hand Scala has some properties that help when working with a simple Editor: you can have more classes in one file so I usually define a whole package in one file which again doesn't grow too large, since Scala class are usually very (or even extremely) small. So I usually have only two or three files open at a time and hence don't need a package/file management.
I couldn't get code folding by languages tags to work but folding by indentation works just fine if you stick to Scala's indentation conventions.
One thing that doesn't work is auto-completion. But then again, this makes me write more loosely coupled objects ;)
Buildr 支持 Scala 和 Java 作为一流语言,支持 ScalaCheck 和 ScalaSpecs,当然也有足够的插件,使其成为 Maven 的有力竞争者。
Buildr supports Scala and Java as first class languages, with support for ScalaCheck and ScalaSpecs, and of course also has enough plugins to make it a good contender for Maven.
只是加上我的两分钱。我认为您也应该尝试一下 Netbeans。它应该是三个主要参与者(Eclipse、Idea 和 Netbeans)中对 Scala 最友好的。
我在 Netbeans 6.8 和 scala-2.8.0.r22602-b20100720020114 中获得了很多乐趣。
可以公平地说,如果没有 Netbeans 插件,我现在就不会进行 Scala 编程。我花了相当多的时间试图让它与其他人一起顺利工作,但没有取得多大成功。
我使用 Netbeans 进行开发,使用 Ant 进行独立构建。有关为 Scala 配置 Ant 的信息,请参见此处:
http://scriptlandia.blogspot.com /2007/04/how-to-compile-and-run-scala-program.html
Just adding my two cents. I think you should give Netbeans a try too. Its supposed to be the most Scala-friendly among the three major players (Eclipse, Idea and Netbeans).
I have been having a lot of fun with Netbeans 6.8 and scala-2.8.0.r22602-b20100720020114
It is fair to say that I wouldn't be programming Scala now if it hadn't been for the Netbeans plugin. I have spent a fair bit of time trying to get it to work as smoothly with the others, but without much success.
I use Netbeans for developing and Ant for standalone build. Info on configuring Ant for Scala here:
http://scriptlandia.blogspot.com/2007/04/how-to-compile-and-run-scala-program.html