Help using scalafx

Can someone help me understand how to use an external library.
I wanted to experiment with ScalaFX.

I tried to copy/paste the example from the web page, and not surprisingly IntelliJ cannot resolve the symbols. I’m pretty sure I need to either download the code and put it somewhere, or I need to tell IntelliJ to do the downloading for me.

Can someone suggest what I need to do? Is it simply adding something to the build.sbt file? Does an entry in the build.sbt file such as this…

libraryDependencies += "org.scalatest" %% "scalatest" % "3.0.5" % "test"

…tell sbt to download the library, or does it promise sbt that I’ve already downloaded the library? I seem to recall that after adding the scalatest lines to the build.sbt file, I didn’t have to explicitly download anything. not sure whether sbt or IntelliJ did it for me on seeing the lines, or whether scalatest was already part of the initial download.

50

  1. Your project must be based on SBT. IntelliJ has integration with SBT, so it can cooperate with SBT and extract project information from build description files. You’ve said that ScalaTest was automatically downloaded after editing build.sbt so probably your project is already based on SBT. What’s your final build.sbt file?
  2. Depending on your settings in IntelliJ a project refresh may be needed. Look into logs to discover if there were any problems during project import from SBT. If import fails then nothing in project configuration changes.
  3. "org.scalatest" %% "scalatest" % "3.0.5" % "test" means that scalatest is only accessible from tests, i.e. from tests/ directory. That’s OK, but you probably don’t want to append test to ScalaFX dependency.

I found a quick-start guide for ScalaFX, which recommend to add to following to the build.sbt file.

libraryDependencies += "org.scalafx" %% "scalafx" % "8.0.144-R12"

When I added this, IntelliJ, asked me some question (sorry I don’t remember the question), but I said yes. It went off and thought for 10 or 15 seconds. Thereafter, IntelliJ is able to resolve the symbols.

Did it download the library? Or did I already have the library?

Probably IntelliJ asked you if the project should be re-imported. Importing takes time as SBT has to download missing libraries, then IntelliJ SBT plugin dumps project description XML to disk, then IntelliJ picks it up, analyzes, updates project and reindexes what has to be reindexed.

1 Like

It tells sbt to download it if it hasn’t yet.

What intellij probably asked you is if you want to reimport from sbt since your build definition changed, and doing so would run sbt, causing the dependency to be downloaded and its location communicated back to intellij.

1 Like