Weird compilation error for cross project

Heyhey,
I have a really weird error with a simple cross compiling project.

The build.sbt looks like so:

ThisBuild / version := "0.1.0-SNAPSHOT"
ThisBuild / scalaVersion := "3.2.2"

lazy val root = crossProject(JSPlatform, JVMPlatform)
  .crossType(CrossType.Pure)
  .in(file("."))
  .settings(
    name := "SimpleXML",
    // https://mvnrepository.com/artifact/org.scalatest/scalatest
    libraryDependencies += "org.scalatest" %%%"scalatest" % "3.2.15" % Test
  )

the plugin.sbt:

addSbtPlugin("org.scala-js" % "sbt-scalajs" % "1.13.1")
addSbtPlugin("org.portable-scala" % "sbt-scalajs-crossproject" % "1.3.1")

and when I run compile, rootJS/test or rootJVM/test everything looks fine, but when I want to run just test then I get this error:

[error] 3 |import org.scalatest.flatspec.AnyFlatSpec
[error]   |       ^^^^^^^^^^^^^
[error]   |       value scalatest is not a member of org

Intellij also notes the same error and wont even compile, luckily the sbt interface at least lets me run the separate tests and compilation. Does anybody know what’s up with that?

1 Like

When you create a crossProject.in(file(".")), that does not actually create any project rooted in ".". Therefore, sbt still creates its own default project in that file. Because you’re using CrossType.Pure, all the sources of your cross-project also appear as sources of that synthetic root project. But the root project has no dependency (it has no settings whatsoever), so its tests do not compile.

Combining CrossType.Pure with in(file(".")) tends to cause that kind of confusion. It’s best to avoid it.

2 Likes

Thank you, I moved everything one level down and now everything seems to work :thumbsup:
Just for clarification, is there a more comprehensive documentation than can be found here

or here?

I don’t think so.