How to open SBT Tool Window in Intellij? - scala

This question may sound silly for you, but I have been searching the Internet for a while and couldn't find the answer. How can I open SBT Tool Window in Intellij (scala and SBT plugins obviously installed)?

In Menu: View -> Tool Windows there should be two entries:
SBT
SBT Console
The first you can use to refresh IDEA project structure from SBT and view dependencies.
The second gives you a console where you can run sbt commands.
Update:
As Justin already aded:
As of IntelliJ IDEA 2017.1 Build #IC-171.3780.52 there is a new and (imho) better way:
(If you are working with an SBT project, that is)
When you open the SBT Tool Window, you will find a new scala terminal icon:
This will open an sbt console session with your sbt project import settings.
One major benefit is that you will actually (finally) get links to your code lines for compiler warnings and errors.

To be able to open SBT Console from View -> Tool Windows you first need to install the plugin required for it.
You can find the SBT plugin by searching for it under Settings -> Plugins -> Browse repositories
Plugin homepage: https://github.com/orfjackal/idea-sbt-plugin

In IntelliJ 2017.1, an sbt shell is integrated with the Scala plugin. You can open it from an icon on the sbt project view toolwindow, or from the "Tools" menu

In Intellij 16 SBT Console menu item no longer exists and in Debian 7 (XFCE) Alt-F12 doesn't work.
To run SBT console:
select View -> Tool Windows -> Terminal (for Alt-F12)
type sbt and console works

You can either use above or simply use Alt+F12

I had an issue where the sbt shell launcher was not on the bottom of the IDE and the sbt was not listed as an option under Tools. Discovered that the issue was after expanding a zip file of a scala project to my workspace, the build.sbt file was not in the root folder of the project structure, but nested one subfolder down. When importing this project into intellij it was not properly configuring it as an sbt project. After removing the project, exploding the zip in such a way that the build.sbt was in the root of the project and reimporting the issue was resolved.

I had a similar, but slightly different issue. First, I didn't have the Scala plugin installed on my version of IntelliJ. Once done, I restarted the app. Then created a new project (even though I was trying to open an existing one). When creating the project I made sure to put the root directory of the project as the root folder of the project I wanted to import (the one that has the sbt file). IntelliJ synched my new project with the existing one and I was good to go.

Related

How can I have more than one project inside IntelliJ IDEA?

I'm switching from Eclipse to IntelliJ IDEA.
In Eclipse I have many Java projects I can open and see the code I need. However, in IntelliJ IDEA I can see only one project at a time.
How can I have more than one project in the IDEA IDE?
This ...
In Eclipse I have many Java projects I can open and see the code I need
... refers to an Eclipse Workspace. There is no direct equivalent to Workspaces in IntelliJ.
IntelliJ provides a help topic titled Migrating From Eclipse to IntelliJ IDEA which maps Eclipse concepts to IntelliJ concepts. In particular, it has this to say about the absence of Workspaces from IntelliJ ...
The first thing you'll notice when launching IntelliJ IDEA is that it has no workspace concept. This means that you can work with only one project at a time. While in Eclipse you normally have a set of projects that may depend on each other, in IntelliJ IDEA you have a single project that consists of a set of modules.
If you have several unrelated projects, you can open them in separate windows.
If you still want to have several unrelated projects opened in one window, as a workaround you can configure them all in IntelliJ IDEA as modules.
You can open more than one project in the IDEA IDE.
In IntelliJ IDEA, you go to File -> New -> Module from Existing Source...
You can refer image to see:
After import your project. You will see result as image:

How to create an Eclipse Scala project in typesafe activator?

I have installed typesafe activator, created a project, added my own Scala classes and successfully compiled and run my code.
Now I was looking for a function to eclipsify my project using activator (similarly to what can be done with play) but I cannot find anything neither on the typesafe website nor by searching the internet.
Does activator provide such a function?
cd to the directory then type activator eclipse
For more options see here: https://www.playframework.com/documentation/2.3.x/IDE
You can do this from the Activator Web UI.
After selecting/opening your project, in the "Your application is ready" pop-up select "Code view & Open in IDE".
In the following code view there's the "Browse code" column.. to the right of the "Browse code" headline, there's a little gear wheel. That will open a menu that let's you open the project outside of Activator:
in SBT type eclipse, in activator select code/edit/eclipse
You need to build your project once so that it downloads the required sbt plugins.
Easy way to build is using the activator ui. Then in the "Code" tab click on "Build Eclipse project" or activator eclipse from the command line.

IntelliJ IDEA: Cannot import SBT project

I'm completely new to development using Play or IntelliJ for that matter. I've created a simple HelloWorld application using Activator, and this is an sbt project.
I've been trying to import this to IntelliJ and this is the screen I'm stuck at:
https://www.dropbox.com/s/we1a4a3184sojvb/Screenshot%202014-07-24%2016.57.11.png
In almost all tutorials I've been through online, I've seen people using an sbt option on the import screen. I've installed the SBT plugin as well, but that hasn't helped. I've restarted IntelliJ several times to no avail.
Where am I going wrong?
I'm running 13.1.4 with the SBT plugin installed.
I had this error when importing a new module from existing sources.
On the right-hand side of your IntelliJ window, you will see a list of vertical tabs, open the SBT tab.
Select the module that's causing trouble, right click on it, select "Detach external project"
Try to import the module again.
Move to /your-project-folder
Run ./activator
Type idea . It will generate IDEA project.
Open (not import) File->Open.. project in IDEA.
I had a similar problem which came from a different place than the other solutions here so adding it in case it occurs for others.
In my case the problem was caused by accidentally opening the IdeaProjects directory. When you do this, it creates the .Idea folder in that directory, and populates it as a project. This apparently also confuses the set import.
The solution is to remove the .Idea folder and open (not import) the directory again.
I encountered the same error when I was trying to import a new scala project A to an existing IntelliJ project B as a module. I solved the problem by following step below:
Go to your folder of project B. Open file .idea/sbt.xml.
Deleting the entry which includes the path of project A.
After a series of struggles, I must say something weird solved this problem – moving to IntelliJ IDEA Ultimate. That has built in Play application support and can run/debug/test the application out of the box, which is very handy.
All I can say after this experience was that JetBrains wants you to upgrade to Ultimate if you want things to work right out of the box.
I'm sure there are ways to get this working with CE also, but I wasn't successful with that.
Solved for
IntelliJ IDEA 2022.2.1 (Ultimate Edition)
scala plugin: 2022.2.12
sbt version: 1.7.1
doing these steps:
Unlink sbt Project(sbt toolbar), then link it again.
Delete modules (ctrl + alt + shift + s).
Remove .bsp/, and .idea/ config files.
Invalidate caches..(ctrl + f).
Restart IDEA.
The number of steps to make it work may vary.
Uninstall everything
Reinstall IntelliJ
Install the JetBrains official Scala plugin
Import the project
Make sure that the project has a build.sbt file in the right place, so that IntelliJ can find it as an SBT project.
This is about IntelliJ IDEA version 13.1.4.
This issue is solved in the latest updates of the SBT and Scala plugins.
Make sure that your java path is correct (IntelliJ can use other path than system defined)
Preferences -> Build, Execution, Deployment -> sbt -> JVM - choose a
correct JRE

sbt build failed in Intellij but I want to open the project anyways

I am trying to import an existing sbt project. As part of the import process IJ attempts to build it. The sbt build fails - and it is due to proxy issues not the culprit of IJ. I want to open the project with existing sources anyways..but am unable to figure out how to do so . When hitting "Finish" in the "import Project" dialog, IJ will do the build.Is there a "skip build" option somewhere?
As a workaround, you may try to generate intellij files from sbt using
sbt gen-idea
or
sbt idea
(the exact command depends on the sbt configuration)
It's always worked for me. I'm using the cmomunity edition.
I have found that the most reliable way to handle sbt projects in IJ is to actually open the file directly from the Finder (mac) / Explorer (windoze) / nautilus (linux/gnome).

How to have Eclipse recognize dependencies from SBT

I am trying to figure out how to make Eclipse recognize dependencies that are retrieved using SBT? SBT download the correct dependencies and puts them in my ~/.ivy directory but eclipse doesn't see them. Is there a way to do this?
thanks
If you are using sbteclipse plugin it's achievable in a simple way. In sbt type:
reload
eclipse with-source=true
Then in eclipse, hit F5 on a project folder to refresh it. Or right-click and choose "Refresh". Just works.
This is probably not the answer you are looking for and I admit it is not elegant but it currently works for me, meaning that I think it takes less time for me to periodically do the following instead of researching and finding a more elegant solution.
I assume you are using the sbt-eclipse plugin ( https://github.com/typesafehub/sbteclipse ). When I add new dependencies to my project ( which is actually pretty rare ) I simply regenerate my eclipse project files from the plugin. The downside of this is that I have a multiple module project and after I refresh the projects in eclipse I need to re-add the inter-project dependencies in the eclipse build path editor.
Like I mentioned it is pretty hacky but all in all I really don't loose that much time doing it. It's not pretty but it works.
Best of luck,
Andy
I use the Apache IvyDE plugin for Eclipse, and I've had more luck with this approach. It's only described in the old sbt docs, but works with sbt 0.11
First, install the IvyDE plugin in Eclipse and restart.
Run the sbt command deliver-local - this will create an XML ivy file of your dependencies.
In Eclipse, under your Project/Properties - Java Build Path - Libraries, click "Add Library" and choose "IvyDE Managed Dependencies" then select the file target/scala-2.9.1/ivy-projectversion.xml
When you add a new dependency to build.sbt, run the sbt commands reload and deliver-local again. Then right-click the Ivy library for your project in the Package Explorer - it will be called "target/scala-2.9.1/ivy-projectversion.xml [compile,test]", and click the second "Refresh" menu item (between "Refresh" and "Reload Settings" - not "F5 Refresh" ).
In command prompt go to the project folder and type
sbt eclipse
This should generate the appropriate .classpath entries in eclipse project.
Go back to eclipse, select the project and press f5, this will reload the referenced libs.
All you need is execute from your project home:
sbt "eclipse with-source=true"
or enter sbt console and write:
eclipse with-source=true
BTW: I don't know if from Jan '12 something has changed but now it seems much more simple.
The following works for me:
1) close project in Eclipse
2) in my file explorer, browse to my Eclipse project, make sure hidden files are visible
3) open .classpath in a simple text editor
4) copy the bottom entry. For example, in my current project, it is <classpathentry path="/home/natalie/.ivy2/cache/org.scalatest/scalatest_2.9.1/jars/scalatest_2.9.1-1.8.jar" kind="lib"></classpathentry>
5) navigate to my .ivy folder, cache, then down to the library I have added via sbt
6) right click on jar file, select properties, copy the path and jar file name and replace it in the entry I copied in step 4
7) save .classpath
8) open my project on Eclipse
New dependency is now available in Eclipse.