Re-opening old project

Can someone help me figure out how to make this not-so-old code work again?

I’m opening a project in IntelliJ which I haven’t opened in a while.
The build.sbt claims it is using scalaVersion 2.13.1. I’m not sure whether IntelliJ honors that scala version or not.

I have reason to doubt, because there is a 2.12 directory but not 2.13 directory in the project/target directory.

Screenshot 2020-04-23 at 15.03.21

The build.sbt file also claims version 12.0.2-R18 of scalafx.

name := "mgs"

version := "0.1"

scalaVersion := "2.13.1"

libraryDependencies += "org.scalacheck" %% "scalacheck" % "1.14.1" % "test"
libraryDependencies += "org.scalactic" %% "scalactic" % "3.1.0"
libraryDependencies += "org.scalatest" %% "scalatest" % "3.1.0" % "test"

libraryDependencies += "org.scalafx" %% "scalafx" % "12.0.2-R18"
libraryDependencies += "org.scala-lang.modules" %% "scala-parallel-collections" % "0.2.0"

val circeVersion = "0.12.3"

libraryDependencies ++= Seq(
  "io.circe" %% "circe-core",
  "io.circe" %% "circe-generic",
  "io.circe" %% "circe-parser"
  ).map(_ % circeVersion)

When I try to run the code again, javafx seems to be missing. I seem to recall this worked the last time I looked at it, but it fails now. I get the following errors.

Error:(58, 26) Symbol 'term javafx.scene.image' is missing from the classpath.
This symbol is required by 'class scalafx.scene.image.WritableImage'.
Make sure that term image is in your classpath and check for conflicting dependencies with `-Ylog-classpath`.
A full rebuild may help if 'WritableImage.class' was compiled against an incompatible version of javafx.scene.
  private val wimg = new WritableImage(width, height)
Error:(223, 14) not found: value javafx
      import javafx.embed.swing.SwingFXUtils._
Error:(228, 13) not found: value fromFXImage
      write(fromFXImage(wimg, null), "png", file)

Screenshot 2020-04-23 at 15.04.23

Looks like there’s a differrent place where the 2.13 dependencies are kept. that’s strange. So perhaps IntelliJ does understand that I’m using Scala 2.13.

Screenshot 2020-04-23 at 15.13.23

project/target is where your build definition itself gets compiled to. sbt 1 build definitions are always compiled using Scala 2.12, regardless of your scalaVersion setting. So that’s why you’re seeing 2.12 in that directory.

I have no firsthand experience with JavaFX, but this looks relevant:

1 Like

Wow, thanks. I’ve added the following lines. Now my project compiles again.

lazy val osName = System.getProperty("") match {
  case n if n.startsWith("Linux") => "linux"
  case n if n.startsWith("Mac") => "mac"
  case n if n.startsWith("Windows") => "win"
  case _ => throw new Exception("Unknown platform!")

// Add JavaFX dependencies
lazy val javaFXModules = Seq("base", "controls", "fxml", "graphics", "media", "swing", "web")
libraryDependencies ++= m=>
  "org.openjfx" % s"javafx-$m" % "11" classifier osName
1 Like