8
votes

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.

3
views -> Tools windows and Select sbt -> then a panel will open on right side of the ide -> Click on the circle button and you won't see this error in ide again.zenwraight
I've tried updating SBT by using the SBT panel on the right - the same issue is still there.svbyogibear
Are you using 2018.1? There seems to be a bug in it. I used to be able to switch to Intellij and it would automatically recognize changes to build.sbt, but it doesn't do that anymore, unless I make the change to build.sbt inside Intellij itself. Or simply close and reopen Intellij. They need to fix this ASAP.ManoDestra
I had also a problem with sbt / intellij - see stackoverflow.com/questions/49815909/… - maybe this helps (cannot tell for sure as your sbt console output is not in the ticket)pme

3 Answers

1
votes

I encountered a very similar problem when upgrading from IntelliJ-Idea 2017.3 to 2018.1

My temporary solution was to revert back to the 2017 version. I found this bug in their bug tracker which I think relates to the problem. https://youtrack.jetbrains.com/issue/SCL-13600

Have you tried with an older version or found a more permanent solution to this yet?

20
votes

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

2
votes

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.