0

I'm writing a cross-compiled library between JSPlatform and JVMPlatform using sbt-scalajs-crossproject. I've explicitly set scalaVersion in common settings and yet:

sbt:oatlibxp> show scalaVersion
[info] oatlibxpJS / scalaVersion
[info]  2.13.11
[info] oatlibxpJVM / scalaVersion
[info]  2.13.11
[info] scalaVersion
[info]  2.12.18                 <<---- WHY?

Why is the last one (the default project) different from the others? For what it's worth, the values for version, scalacOptions, etc are also different.

Here is my build.sbt (I've removed some settings like libraryDependencies that I think are not relevant):

val sharedSettings = Seq(
  version      := "3.0.0-SNAPSHOT",
  name         := "oatLibXP",
  scalaVersion := "2.13.11",
  scalacOptions ++= Seq("-feature", "-deprecation", "-unchecked"),
)

lazy val oatlibxp = crossProject(JSPlatform, JVMPlatform)
  .crossType(CrossType.Full)
  .in(file("."))
  .settings(sharedSettings)

And my directory structure:

% tree -d -L 3 -I target
.
├── js
│   └── src
│       └── main
├── jvm
│   └── src
│       ├── main
│       └── test
├── project
│   └── project
└── shared
    └── src
        ├── main
        └── test

14 directories

Version numbers:

  • sbt: 1.9.0
  • sbt-scalajs-crossproject: 1.2.0
  • sbt-scalajs: 1.13.0
bwbecker
  • 1,031
  • 9
  • 21
  • I think [sbt basic def](https://www.scala-sbt.org/1.x/docs/Basic-Def.html) should help. If you set `ThisBuild / scalaVersion := "2.13.11"` you will have that version set for all the projects you define in your `build.sbt` – Gastón Schabas Jun 23 '23 at 20:45
  • @GastónSchabas -- Thank you. Just checked and that does work. But why is it necessary? [SBT Multi-project builds](https://www.scala-sbt.org/1.x/docs/Multi-Project.html) talks about `ThisBuild` and then says "Another way to factor out common settings across multiple projects is to create a sequence named commonSettings and call settings method on each project." Any idea why my common settings isn't working? I'll also point out that my approach is what's shown in the sbt-crossproject documentation. – bwbecker Jun 23 '23 at 21:05

1 Answers1

1

That's the value of the setting for the root project, which is only an aggregate. So it doesn't really matter. If, for your peace of mind, you still want it to be the same, I recommend you put this at the top level of your build:

ThisBuild / scalaVersion := "2.13.11"
sjrd
  • 21,805
  • 2
  • 61
  • 91
  • Thanks, @sjrd. But the same question that I addressed to Gastón Schabas' comment. Why does the common settings give a different behaviour when the SBT documentation seems to imply they are equivalent? – bwbecker Jun 23 '23 at 21:12
  • The common settings are equivalent as long as you have a single `project` in your build. A `crossProject` creates 2 `project`s, and then a third synthetic one is automatically created at the root of the build. The common settings apply to the 2 projects behind the `crossProject`, but not to the root project. – sjrd Jun 24 '23 at 10:32
  • Thanks for the explanation, @sjrd. – bwbecker Jun 25 '23 at 13:28