Skip to content

Duplicate scala3-library_3 with conflicting versions set on the classpath #826

@WojciechMazur

Description

@WojciechMazur

Related to scala/scala3#22890

Since 3.7.0 we've discovered cases in the ecosystem where 2 different versions of scala3-library where present on the classpath. Previously it was not an issue, as these were binary compatible. Since 3.7.0 however there was a breakage related to experimental definitions, which is allowed. This has however caused issues in non-experimental code. We've found out that it was coused by having multiple scala3-library entries on the calsspath due to missconfiguration, eg. when usinglibraryDependencies := instead of libraryDependencies ++= (fixed since sbt 1.10.0)

Currently Scala 3 compiler mitigates this known issue by reporting a warning, but the problem might arise again in the future.
Currently there seems to be issue related to projects cross-build for Scala.js using sbt-typelevel plugin.

As an example we can examine https://github.com/typelevel/spotted-leopards
When running

clean;++3.7.2!;coreJS/Test/compile

we'd get

[info] Forcing Scala version to 3.7.2 on all projects.
[info] Reapplying settings...
[info] set current project to repo (in build file:/Users/wmazur/projects/scala/community-build3/repo/)
[info] compiling 20 Scala sources to /Users/wmazur/projects/scala/community-build3/repo/core/js/target/scala-3.7.2/classes ...
[warn] package scala contains object and package with same name: caps.
[warn] This indicates that there are several versions of the Scala standard library on the classpath.
[warn] The build should be reconfigured so that only one version of the standard library is on the classpath.
[warn] one warning found
[info] compiling 3 Scala sources to /Users/wmazur/projects/scala/community-build3/repo/core/js/target/scala-3.7.2/test-classes ...
[warn] package scala contains object and package with same name: caps.
[warn] This indicates that there are several versions of the Scala standard library on the classpath.
[warn] The build should be reconfigured so that only one version of the standard library is on the classpath.

The same issue exists in default 0.5.4 version of sbt-typelevel plugin and it's latest version 0.8.0

However, if we'd do the same when not using sbt-typelevel plugin

-val sbtTypelevelVersion = "0.5.3"
-addSbtPlugin("org.typelevel" % "sbt-typelevel" % sbtTypelevelVersion)
-addSbtPlugin("org.typelevel" % "sbt-typelevel-site" % sbtTypelevelVersion)
-addSbtPlugin("org.scala-js" % "sbt-scalajs" % "1.13.2")
+addSbtPlugin("org.portable-scala" % "sbt-scalajs-crossproject"      % "1.3.2")
+addSbtPlugin("org.scala-js"       % "sbt-scalajs"                   % "1.13.2")

we'd get no warnings

[info] compiling 20 Scala sources to /Users/wmazur/projects/scala/community-build3/repo/core/js/target/scala-3.7.2/classes ...
[info] compiling 3 Scala sources to /Users/wmazur/projects/scala/community-build3/repo/core/js/target/scala-3.7.2/test-classes ...
[success] Total time: 4 s, completed Jul 31, 2025, 10:20:37 AM

It's hard to what couses that, it might also be triggered by some of plugins added as dependenices to sbt-typelevel

When running show coreJS/fullClasspathAsJars

> show coreJS/fullClasspathAsJars
[info] * Attributed(<Repo>/core/js/target/scala-3.7.2/spotted-leopards_sjs1_3-0.1-05e2260-20250731T082503Z-SNAPSHOT.jar)
[info] * Attributed(<Coursier>/maven2/org/scala-lang/scala3-library_sjs1_3/3.7.2/scala3-library_sjs1_3-3.7.2.jar)
[info] * Attributed(<Coursier>/maven2/org/scala-js/scalajs-library_2.13/1.19.0/scalajs-library_2.13-1.19.0.jar)
[info] * Attributed(<Coursier>/maven2/org/scala-lang/scala-library/2.13.16/scala-library-2.13.16.jar)
[info] * Attributed(<Coursier>/maven2/org/scala-js/scalajs-javalib/1.19.0/scalajs-javalib-1.19.0.jar)
[info] * Attributed(<Coursier>/maven2/org/scala-js/scalajs-scalalib_2.13/2.13.16%2B1.19.0/scalajs-scalalib_2.13-2.13.16%2B1.19.0.jar)
[info] * Attributed(<Coursier>/maven2/org/scala-lang/scala3-library_3/3.3.1/scala3-library_3-3.3.1.jar)

We can clearly see that scala3-library_sjs1_3-3.7.2 added by Scala.js sbt plugin is set to correct version
At the same time, there seems to be injected scala3-library_3-3.3.1 by one of the other sbt plugins (3.3.1 is the default scala version set in this project)

That's not the case for coreJVM project

> show coreJVM/fullClasspathAsJars
[info] * Attributed(<Repo>/core/jvm/target/scala-3.7.2/spotted-leopards_3-0.1-05e2260-20250731T082503Z-SNAPSHOT.jar)
[info] * Attributed(<Coursier>/maven2/org/scala-lang/scala3-library_3/3.7.2/scala3-library_3-3.7.2.jar)
[info] * Attributed(<Coursier>/maven2/org/scala-lang/scala-library/2.13.16/scala-library-2.13.16.jar)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions