Run SBT Task from Eclipse
Asked Answered
A

2

20

I am using SBT as a build manager, and Eclipse as my IDE, or at least I want to. The problem is more, how do I run specific SBT tasks from Eclipse. I have properly exported the project to Eclipse, and Eclipse is very helpful while writing the code, but how can I use Eclipse as a frontent for SBT. How can I start an SBT run command from eclipse? How can I start an SBT test command?

Angora answered 19/3, 2012 at 22:2 Comment(2)
There is a plug-in that adds an option to run the sbt console associated to any scala project in Eclipse. github.com/SandroGrzicic/sbtconsoleUnintelligent
You could check my answer on this question: [Using SBT from Scala IDE][1] [1]: https://mcmap.net/q/422309/-using-sbt-from-scala-ide/…Aspirate
A
11

Unfortunately, at the moment, there is no integration of SBT in eclipse. The sole plugin that goes in that direction seems abandoned and is quite useless: http://www.assembla.com/spaces/sbt-eclipse-integration/wiki

A solution is to integrate a terminal into eclipse to run sbt command. If you want to do it, the documentation is here: Is there an Eclipse plugin to run system shell in the Console?

If you are open to other IDE, and if integration is mandatory for you, you can use IDEA and its SBT plugin: https://github.com/orfjackal/idea-sbt-plugin

As far as I'm concerned, I keep using a shell window beside my eclipse, using key shortcut to switch between them.

Altonaltona answered 19/3, 2012 at 22:32 Comment(6)
I do know IDEA, used it and liked it, but it is even more resource hungry than eclipse. But the reason I gave eclipse a chance is that my Keyboard layout does not work perfectly (some characters are missing)on anything swing related.Angora
Eclipse is definitely not bad for eclipse development, but its support for sbt is clearly not good enough at the moment. But we can hope it will improve in the future.Altonaltona
iinm, the occasions when you run sbt commands are typically few and far between, so Eclipse integration isn't in high demand. Especially with, e.g., the play 2.0 framework, you just open a terminal and sbt run, and leave it running as you develop.Pasadena
If you don't want to rely on a extra plugin for continuous testing and/o TDD approach (i don't even know if existing eclipse plugin works in a scala scenario), you run a lot of sbt command.Altonaltona
Sandro Grzicić is working on integrating a sbt-console (GSoC project), and hopefully we will also have a SBT-aware editor (i.e. code completion on your Build.scala files). If you want to follow development, simply subscribe to the scala-ide-dev MLReadiness
I just tried this and the commands I typed would not be passed to sbt unless I launched it with -Djline.WindowsTerminal.directConsole=false, as in my answer below.Zola
Z
5

At of today I managed to launch sbt as as external tool in eclipse on Windows. This was straightforward apart from having to guess an undocumented jline property

-Djline.WindowsTerminal.directConsole=false

Pressing enter after typing a command does nothing unless this property is set.

For reference purposes, this is with mostly current versions of everything:

  • Windows 7 x64
  • Eclipse 4.3.1
  • Scala IDE 4.0.0m1
  • sbt 0.13.0

The run configuration looks like this: eclipse run config screenshot

HTH

Zola answered 12/2, 2014 at 21:52 Comment(3)
do you restart sbt with each start/build of the program?Angora
With this launch config what you get is an sbt prompt, and you can just type more commands into it when you want to build something, so it is not necessary to restart sbt between builds.Zola
At the moment it is not important, because I have neither eclipse installed, not do I use Scala or the Jvm at all in any of my projects, but It would be good to know, weather this allows to bind an sbt task to a key in eclipse.Angora

© 2022 - 2024 — McMap. All rights reserved.