Kevin
Kevin

Reputation: 6292

Add dependencies to sbt build.scala file does not have effect in IntelliJ

I am new to SBT.

I tried to add an dependency into the SBT's build.scala file using IntelliJ.

Here is my build.scala:

import sbt._
import Keys._

object MyBuild extends Build {
  libraryDependencies ++= Seq(
    "com.mycompany" % "mylibrary" % "0.1-SNAPSHOT"
  )
}

When I was using Mave, any dependencies added to the pom is automatically pick up. But when I add this line into the build.scala, the library is still not available for me to use in IntelliJ.

I am wondering what else I shall do to load this dependency? I have got the sbt plugin for intelliJ installed.

Many thanks.

Upvotes: 2

Views: 2298

Answers (2)

Devis L.
Devis L.

Reputation: 312

UPDATE: Found this https://confluence.jetbrains.com/display/IntelliJIDEA/Getting+Started+with+SBT mentioning the "refresh" button (under 5. Add a Dependency to an SBT Project), which works fine.

--

IntelliJ has now integrated SBT support into the Community edition, however this is still an issue. The old plugin doesn't seem to exist anymore, i.e. links are broken and releases are outdated. One solution that seems to work is reimporting the project everytime a new dependency is added, which is a very time consuming task though.

Another trick is adding the dependency manually from the project settings:

Project Structure->Project Settings->Libraries

  • Click the "+" and select "Java"
  • Find the JAR in your ivy cache, e.g. under ~/.ivy2/cache/

Upvotes: 0

0__
0__

Reputation: 67280

Are you using the JetBrains plugin? Because that is the only one that claims to support automatic project update.

With the sbt-idea plugin, you'll have to close the project, run sbt gen-idea, and re-open the project after you change dependencies.

Upvotes: 3

Related Questions