Could not find package scala from compiler core libraries

Don’t know exactly what happened. Recently I start switching a project to scala 3.4.1 with sbt 1.9.7. The code gets compiled without a problem, but after adding scalatest, the sbt complains Could not find package scala from compiler myorg libraries. My build.sbt is as below

ThisBuild / organization := "myorg"
ThisBuild / scalaVersion := "3.4.1"

lazy val myorg = (project in file("myorg"))
    .settings(
        scalaVersion := "3.4.1",
        libraryDependencies := Seq(
          "org.scalatest" %% "scalatest" % "3.2.18" % Test
    )
)

lazy val root = (project in file(".")).dependsOn(myorg)

If I follow scalatest’s instruction where it mentions to use %%%. sbt will complains

build.sbt:8: error: value %%% is not a member of String
    "org.scalatest" %%% "scalatest" % "3.2.18" % Test

How to fix this error? Thanks.

1 Like

The %%% is a part of GitHub - portable-scala/sbt-crossproject: Cross-platform compilation support for sbt. API - it’s an sbt plugin allowing for better handling of Scala.js and Scala Native dependencies.
For normal codebases (using only Scala on the JVM) use %%

Quick cheatsheat what %{1, 3} does:
Assume you’re using Scala 3 and Scala Native 0.5

  • "org" % "artifact" % version - would be interpreted directly as `org:artifact:version’ - it can be used for Java dependencies
  • "org" %% "artifact" % version - would be interpreted as`org:artifact_3:version’ - version of library cross compiled for given binary Scala version - normal way of dealing with Scala dependencies
  • "org" %%% "artifact" % version - would be interpreted as`org:artifact_3_native0.5:version’ - version of library cross compiled for both binary versions of Scala and Scala Native/Scala.js - used for Scala Native / Scala.js dependencies
4 Likes

Regarding the Could not find package scala from compiler myorg libraries. - I assume it’s this one exception in the compiler scala3/compiler/src/dotty/tools/dotc/MissingCoreLibraryException.scala at 63810dca83be96b29097acf6c554808932466d1a · scala/scala3 · GitHub

You can check if there might be multiple scala-library entries on the classpath (probably explicit, transitive dependencies would be handled by eviction). Can’t really tell what else might be causing that. There might be also a case, where some syntax issue leads to this exception - you can try to termporaly comment out/delete part of the test sources to try find out which file couses that, altough it seams unlikely

2 Likes
2 Likes

@bjornregnell

Blockquote
Yes that’s right! Your tests won’t run and it will claim success !!

You’ve let the genie out the bottle now - corporate developers the world over will be celebrating wildly tonight. There’s no going back… :anguished:

1 Like

Lol. No tests means no trouble. (Yet…)

1 Like

Ok. After battling several days, eventually I find what went wrong. It should be

libraryDependencies ++= Seq( ... )

not

libraryDependencies := Seq( ... ) 

The assignment := to libraryDependencies leads to this weird error. By the way, this project I don’t use any ScalaJS, Scala Native. It’s simply a plain Scala 3 project; and I merely added a Hello world main and test classes. Many thanks.

2 Likes