How to log commands issued from Intellij with Scala plugin to SBT - scala

I worked some time with SBT and a text editor. Then, moved to Intellij, installed Scala plugin, and created a new project as in the picture here by choosing it to be based on SBT. Also, in the settings, I chose the SBT launcher to be custom, and made it point to the already-installed sbt.
I believe Intellij is probably calling SBT commands like sbt run and stuff in the background. My question: How can I see (a log of) these commands as they're called by Intellij to sbt and their responses? And as a plus: where can I edit them? I opened the "Edit Configurations" but couldn't find anything like sbt compile.
I believe Intellij shows the responses (e.g., [info] downloading...) below in the "Background Tasks", but
1. It doesn't log these responses and
2. It doesn't show the commands issued by Intellij to sbt.
Big picture/what I'd really want to do: have the IntelliSense features from Intellij and Scala plugin, but build and run from the terminal and not have any effects from Intellij on that.

The IntelliJ Scala plugin doesn't (yet) call sbt except for project import/refresh or if you have a run configuration that uses sbt. Compilation is done by the built-in compile server. If you prefer to use IntelliJ as an editor and run tasks from the sbt console, that usually works fine.

I don't understand the question well
do u want to see the SBT output? if you are using run/debug you will see both the command & the output in the run window (alt+4)
also intelliJ has a window called event log
I hope that help

Intellij reads the projects configuration from sbt and creates an equivalent configurations for its project format (either .idea folder or .ipr)
this is a similar question to yours but about maven, you may find helpful:
https://stackoverflow.com/a/30167052/2675679

Related

SBT Console in Intellij

I am beginner in Scala. I cant find how to add SBT Console.
I have sbt shell, but in Scala course i see that they have both: SBT Shell and SBT Console, and using the second one. I tried to write "console" in sbt shell, and after "run", but it says:
error: not found: value run.
So I just want to add somehow this SBT Console, to run my program not only from button "run" in Intellij.
And what about SBT? Is it really needed? Or can i dont use it for Scala?
You're probably confused by "Shell" and "Console" usually being synonyms, but they actually mean different things with sbt.
sbt shell - is, uhm, a shell that sbt gives you when you run it in interactive mode - i.e. when you just run sbt from your terminal. This gives you access to other exciting things, such as running the app (with run command), inspecting the build (inspect ...), running tests (test, obviously) and so on.
sbt console - is an interactive REPL (read-evaluate-perform-loop) that gives you scala as an interpreter - i.e. you can type in (or paste) some scala code, and it will be immediately compiled and evaluated - outputting the results. Sbt console is also available from sbt shell - by running console.
So, in order to run your program, you have two options (besides the IntelliJ "run" dialog):
From your terminal do sbt run
From your terminal do sbt, then wait for sbt to initialize, then in the sbt shell do just run.
Refer to sbt docs for more details on different ways to run sbt (spoiler: there's also "batch" mode, where you can run sbt run from your terminal - and it is exactly the same as sbt and then run).
Sbt Reference manual might also be helpful - specifically it covers the sbt console command.
And what about SBT? Is it really needed? Or can i dont use it for Scala?
It is not mandatory - you can run scala with maven, it's just a bit more involved to configure. However, if you allow a bit of personal opinion, I'd recommend using sbt with scala projects (and even with Java projects). For one simple reason - the build definition in sbt is essentially just scala code - you can use any language features, third part libraries and even custom code in your build - which sometimes comes very helpful. Compared to maven, I think it's a big step forward, as in maven you define the build using a XML-based "language" defined by the mvn tool and it's plugins - which is much less customizable.
However, gradle also has this advantage, so pick the tool that best suits your needs.

SBT eclipse command issue on multi-project

I imported an eclipse project from an sbt multi project.
The sbt eclipse command did complete normally
But the resulting eclipse project is full of errors as dependency between sub projects are not seen.
I think the sbt plugin is failing on multi projects, or am I missing something.
The project run from sbt runs flawlessly.
But I have no IDE support.
I tried Idea, the multiproject loads flawlessly, but the type indication on flyover is super slow and very often freeze Idea, it is unusable.
Eclipse as tons of errors because of depencies, but for the type recognised, it gives them very quickly.
I hope somebody has a solution.
I guess that you must run "sbt eclipse" from the root sbt project directoy, and then, when importing into eclipse, click the checkbox "search for nested proyects". That will create a separate proyect for any of the multiple sbt subprojects. And the references between them will be found.

How to run tests on every code change in IntelliJ IDEA from Scala sbt project?

I have a new Scala/sbt project set up in IntelliJ IDEA with ScalaTest and jUnit interface successfully installed as dependencies. I have one test that passes when I hit run or debug.
My problem is that it doesn't rerun if I change something. I have to hit run or debug again and then it runs and gives the expected response.
How do I set up IntelliJ IDEA (with or without sbt) to run all tests every time the code changes? Is it possible to run the tests related to the files that were changed only?
As answered in comment by Boris the Spider you can run
> ~test
from sbt shell. Hopefully sbt and IntelliJ can integrate better via sbt server, but I don't think it's currently possible.

How to use existing Intellij projects as a I move forward with SBT?

Novice SBT question - Now that I've started with some basic SBT tutorials, I'd like to start using SBT build files (within Intellij) a lot more often. However, there's a couple of problems with this :
1) Existing projects that I currently publish to a jar, and later import into other projects... how do I publish this jar file to my local repository? SBT publish-local doesn't seem to fit my situation, because the project was made in Intellij and is not (yet) an SBT project.
2) Suppose I do convert the project to an SBT build setup (and then import it into Intellij).. how do I configure Intellij to to publish-local (update) each time I build the project? I do not see many configurable settings around SBT within the new Intellij SBT support.
Using Intellij 13 and SBT 0.13.1
Thanks!
to get you started up quickly on using SBT to drive Idea, have a look at my template project called skeleton
It supports most of the basic tasks you'd want to do.
To publish to your repository, use the publish task.
hope that helps!
For publishing, you simply use the publish action:
To specify the repository, assign a repository to publishTo and optionally set the publishing style. For example, to upload to Nexus:
publishTo := Some("Sonatype Snapshots Nexus" at "https://oss.sonatype.org/content/repositories/snapshots")
As for your second question, despite being a JetBrains fanboy, I have found SBT integration quite disappointing. For one thing, as the JetBrains documentation states itself, you need two plugins: their plugin and sbt-idea. You use sbt-idea to synchronize the IDEA module structure with the SBT build, and you use JetBrains' idea-sbt-plugin to execute SBT tasks in the "Before Launch" action in Run Configurations.
It sounds like you want to do an "install" on every build, so "Before Launch" action support isn't useful. I would suggest writing your own custom SBT task to install on build and using the Command Line Tools Console to execute that task with SBT as if from the command line. I know; that indirection is annoying.
Bear in mind one more thing. I have found numerous bugs with idea-sbt-plugin. At least on Mac. JetBrains told me the next version will be much better, and you can see for yourself with the next EAP version.
I certainly welcome others who have managed to have more success than I have to chime in.

sbt & Play 2.0 Debugging Information Missing

I am using sbt to build my Play 2.0 project. I managed to configure sbt to open a debugging port, attach an Eclipse remote debugger and enter a break point. I put the break point into one of my actions. But when the execution stops there, I cannot inspect any variable. I guess that sbt builds the Scala code without debugging information.
Does anybody know how to configure sbt to add debugging information? Or could it be a problem of my Scala IDE plugin for Eclipse or anything else?
Many thanks in advance!
To start Play in debug mode via sbt, run:
sbt -jvm-debug 9999 run
I did not find a solution for all problems I have with debugging but at least it works so that I can use it. Here is my status:
I am using sbt directly and cannot use -jvm-debug 9999. But I added the following to JAVA_OPTS in the sbt launch script:
-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=9999
This gives the possibility to connect an Eclipse remote debugger and get debugging information (if running Play in development mode).
The problem that still remains is that I don't get the popups showing variable information when pointing the mouse cursor on a variable. But this seems to be a problem with the Scala IDE plugin and not with Play, because I get the variable information in the variables view in the debugging perspective.
I found this to be the easiest solution : (using IntelliJ IDEA )
in IntelliJ :
Go to "edit run configurations"
Create a new remote configuration (port 9999, all other details leave with default values)
Go back to IntelliJ and run the new debug configuration (don't forget to put a break point)
From command line run :
sbt -jvm-debug 9999 run
I had the same problem in a modularized sbt build. Adding
javacOptions ++= Seq("-g")
to the build.sbt file, solved the problem of missing debug information in the compiled classes.