Incerteza
Incerteza

Reputation: 34884

How to build Scala applications in Sublime Text 3?

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]

Upvotes: 8

Views: 12868

Answers (5)

Yuri
Yuri

Reputation: 1

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

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

Upvotes: 0

gwenzek
gwenzek

Reputation: 2944

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.

Upvotes: 1

Bolek Tekielski
Bolek Tekielski

Reputation: 1214

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.

Upvotes: 1

Seth Tisue
Seth Tisue

Reputation: 30453

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

Upvotes: 4

Jacek Laskowski
Jacek Laskowski

Reputation: 74669

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

Upvotes: 4

Related Questions