Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SBT not loading properly in Intellij-Idea (no SBT external Imports)

The issue I have is with a particular scala project of mine when it comes to using the imports from my .sbt file. What I expect to happen is when I open up my project by selecting

Open > New Project > Select my SBT

is that my dependencies are loaded as per usual and everything outlines in my SBT file can be found in the project's External Libraries.

When I do import the project I am prompted to update the SBT it indicates that its updating everything and pulling from the SBT sources, but in reality it does not actually reflect any imported items (which also leaves my build.sbt file to have red-underline items as these libraries have not been imported).

A sample of the External Libraries:

external libraries

A sample from my build.sbt:

build.sbt

I have uninstalled, re-installed both IntelliJ and all the plugins, removed my SBT items, added them in again, restarted, rinse repeat until infinity.

I've also opened up the SBT tools window and refreshed SBT as well as removed everything from the list and added it in again with no success.

With that, I have also deleted the generated .idea file and re-imported the project multiple times, using multiple different settings. (Removing the .idea file every time I tried something new).

I have tested the exact same project on a colleague's machine with working results, so I am not sure if there's anything I have configured incorrectly. We compared but everything looks exactly the same.

Cleaning, compiling and running the SBT in terminal works 100% - and this issue does NOT persist when I create a new Scala project. Theres also no error output which is REALLY frustrating.

I've tested with the following:

IntelliJ IDEA 2018.1.1 (Ultimate Edition)

Build #IU-181.4445.20, built on April 2, 2018

JRE: 1.8.0_152-release-1136-b27 x86_64

JVM: OpenJDK 64-Bit Server VM by JetBrains s.r.o

macOS 10.13.3

Scala Plugin 2018.1.8

scala v2.12.4

SBT 1.1.1

** EDIT To give more information, when I have a simple build.sbt file (aka I give it a scala version, a name and some library dependencies) it works completely fine.

When I start adding in different aggregates under the root, it appears to stop recognising those modules.

As an example, I have;

lazy val root = Project("scala-test", file("."))
  .aggregate(core)

If I check my SBT side panel I see everything listed:

enter image description here

Yet they are not in my project structure, meaning that it does not recognise any of the internal imports or import paths:

enter image description here

It appears to be something that's wrong with the Scala plugin but I have not found a stable solution around this.

like image 538
svbyogibear Avatar asked Apr 10 '18 21:04

svbyogibear


People also ask

How do I get sbt tab in IntelliJ?

The sbt tool window is enabled automatically when you create or open your sbt project. Click sbt on the right sidebar to open the tool window. The tool window displays the sbt linked projects, their tasks, dependencies, and all changes made to the underlying build.

What does sbt reload do?

This is used to automatically reload the project when the build files (e.g. build. sbt) are changed.

How compile sbt project in IntelliJ?

Press Ctrl+Alt+S to open the IDE settings and select Build, Execution, Deployment | Build Tools | sbt. In the sbt projects section, select a project for which you want to configure build actions. In the sbt shell section, select the builds option. Click OK to save the changes.


2 Answers

Have you also removed .idea folder and opened the project again.

This helps for me most of the time.

I only use File -> Open... then selecting the directory that contains the build.sbt.

This is how I configure the new project:

sbt project config

like image 71
pme Avatar answered Sep 20 '22 05:09

pme


This worked for me.

cd <project-directory>

# only run this line if you haven't import project into intelij
mkdir -p .idea

touch .idea/sbt.xml

cat > .idea/sbt.xml << EOM
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
    <component name="ScalaSbtSettings">
        <option name="customVMPath" />
        <option name="linkedExternalProjectsSettings">
            <SbtProjectSettings>
                <option name="externalProjectPath" value="$PROJECT_DIR$" />
                <option name="modules">
                    <set>
                        <option value="$PROJECT_DIR$" />
                        <option value="$PROJECT_DIR$/project" />
                    </set>
                </option>
                <option name="sbtVersion" value="1.4.6" />
            </SbtProjectSettings>
        </option>
    </component>
</project>
EOM

I used the sbt version 1.4.6 for my setup but feel free to change it to your preference.

Once you did the following, open the project in intelij and then under menu bar View/Tool Windows sbt will appear and when you open your build.sbt file it will recognise the syntaxes.

like image 44
Mahan Hazrati Sagharchi Avatar answered Sep 21 '22 05:09

Mahan Hazrati Sagharchi