8

I'd like to be able to build Scala applications in Sublime Text 3 on Mac 10.9.3. I have Scala 2.11.1 and sbt 0.13.5 installed and they all work fine. I installed them by homebrew.

However, I can't seem to find how to create a build system for Scala projects. For example, this one doesn't work:

{
    "cmd": ["sbt", "test"],
    "selector": "source.scala",
    "working_dir": "${project_path}"
}

I found a couple of different ones as well but they didn't work for me, either. Your thoughts?

UPDATE:

[Errno 2] No such file or directory: 'sbt'
[cmd: ['sbt', 'test']]
[dir: /Users/alex/Documents/projects/scala/dir1]
[path: /usr/bin:/bin:/usr/sbin:/sbin]
[Finished]

UPDATE2:

{
    "cmd": ["/usr/local/bin/sbt", "test"],
    "selector": "source.scala",
    "working_dir": "${project_path}"
}

An app:

class MainTest extends App {
  println("Hellowa!")     
}

The output:

 [0m[[0minfo[0m] [0mSet current project to scala (in build file:/Users/alex/Documents/projects/scala/)[0m
[0m[[0minfo[0m] [0mCompiling 1 Scala source to /Users/alex/Documents/projects/scala/target/scala-2.10/classes...[0m
[0m[[32msuccess[0m] [0mTotal time: 4 s, completed Jun 16, 2014 4:51:38 PM[0m
[Finished in 7.2s]
Incerteza
  • 32,326
  • 47
  • 154
  • 261
  • 1
    What do you mean when you say "they don't work"? Do you get any error messages, and if so what are they? Does this command work from Terminal? You need to give more information if you want anyone to help you... – MattDMo Jun 15 '14 at 14:49
  • @MattDMo, I'll post them later on. – Incerteza Jun 16 '14 at 01:58
  • @MattDMo, sbt by itself works fine when run from the Terminal. – Incerteza Jun 16 '14 at 04:29

5 Answers5

4

Could SublimeSBT that's "Scala SBT build tool integration for Sublime Text 2 and Sublime Text 3." be a solution?

Jacek Laskowski
  • 72,696
  • 27
  • 242
  • 420
4

Homebrew installs executables in /usr/local/bin, but the error text you have now provided shows that that directory isn't in your path.

Two ways you could fix it:

1) Change "cmd": ["sbt", "test"], to "cmd": ["/usr/local/bin/sbt", "test"],

2) Add /usr/local/bin to your PATH environment variable. Note that you'll need to do this in such a way that GUI apps like Sublime Text notice the change; see e.g. Setting environment variables in OS X? for details

Community
  • 1
  • 1
Seth Tisue
  • 29,985
  • 11
  • 82
  • 149
1

Personally I use SublimeREPL that support SBT. SublimeREPL allows you to launch SBT from Sublime. This avoided me to download another package, cause I already used SublimeSBT for python. I wanted a minimal configuration to code in scala, because my IDE was to slow. I first try to use my on build system but end up using SBT. The SBT offers great advantages in comparaison to other way of building your project.

First it compiles only files that need to (those who have been modified, and those who depend on them). Second it's very handy for importing library. One line into your build.sbt file allows you to import library from github (usually this line is explicited on the github main page). And third you can compile on every save, with the command "~compile", or "~; compile; runMain 'mainclass' "

I find the later pretty useful as it is often long to compile with scala. I often start to add a simple function, save, and while it's compiling I improve my first draw.

The main constraint is you have to put your code in src/main/scala or src/main/java if you have some Java files too, and you have to open the whole root directory with sublime.

gwenzek
  • 2,816
  • 21
  • 21
1

Why wouldn't you :D I am using SublimeSBT for quite some time, and the only complexity it's invoking cmd+shift+p followed by sbt start continuous testing. I would advice you to give SBTSublime a try before baking your own build system.

Bolek Tekielski
  • 1,194
  • 2
  • 10
  • 25
  • why not to add a single line into Scala.sublime-build file instead? – Incerteza Jun 16 '14 at 08:46
  • Sure, but this is kind of a Christmas vs Easter discussion, isn't? My advise is to try the SublimeSBT, as you can have it running in seconds, and remove in the very same amount of time, but if you choose to go your own way, and it works for you - even better. – Bolek Tekielski Jun 16 '14 at 12:46
0

Windows only! If you already add the bin folder to the PATH variable:

{
    "cmd": ["sbt.bat", "test"],
    "selector": "source.scala",
    "working_dir": "${project_path}"
}
Yuri
  • 1