Unifying SBT syntax `%%%` (JS/Native) and `%%` (JVM) for library dependencies


#1

Quoting https://www.scala-js.org/doc/project/dependencies.html
"
To be able to use a Scala library in Scala.js, it has to be separately compiled for Scala.js. You then can add it to your library dependencies as follows:

libraryDependencies += "org.scala-js" %%% "scalajs-dom" % "0.9.5"

Note the %%% (instead of the usual %% ) which will add the current Scala.js version to the artifact name

Note that you can also use %%% in a Scala/JVM project, in which case it will be the same as %% . This allows you to use the same libraryDependencies settings when cross compiling Scala/JVM and Scala.js.
"


As both a library user and a library maintainer, this seems confusing to me (choosing the proper syntax and documenting both syntax options) . Why do we have two syntax options that do the same thing, but only one is valid in some situations? I’m aware there must be some technical reasons behind this, but shouldn’t we just deprecate one syntax and have a unified way of doing things?


#2

Why do we need an extra % to disambiguate between JVM and non-JVM, but nothing to disambiguate between Native and JS?


#3

they don’t do the same thing. %%% is platform sensitive, while %% isn’t. to summarise (assuming Scala 2.12.something and Scala.js 0.6.something):

  • "org.scalacheck" %% "scalacheck" % "1.13.4" means “scalacheck_2.12” for all platforms, and
  • "org.scalacheck" %%% "scalacheck" % "1.13.4" means “scalacheck_2.12” on jvm and “scalacheck_sjs0.6_2.12” on Scala.js (and something else on Scala Native, not sure what)

if the authors of sbt-crossproject are happy to call the behaviour stable, I’d be for folding it into sbt proper.


#4

The behavior is so stable that we have consolidated it into a separate sbt plugin, sbt-platform-deps, for which we released v1.0.0. So basically it will never change ever again.


#5

%%% is used for native too, IIUC.

However even not on the jvm there are rare times you don’t want the platform artifact suffix and so you need to use %%.


#6

Yes, and sbt-platform-deps is now precisely a common dependency of sbt-scalajs and sbt-scala-native.