question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Consider scoping the scala version only in ThisBuild or in Global

See original GitHub issue

problem

scalaVersion is scoped for every build. This often causes problems when people want to set their scala versions globally, because they are overriden by the sbt defaults.

expectation

When people override the scala version in Global or in ThisBuild, sbt should pick up the scala versions from there since sbt does not scope sbt version to every project.

notes

I am not sure this is technically possible. But I think it’s an interesting effort that will make sbt more intuitive. @olafurpg has complained several times that this is the current behaviour.

sbt version: 0.13.x and 1.x.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:10 (10 by maintainers)

github_iconTop GitHub Comments

1reaction
dwijnandcommented, Jul 25, 2017

Due to the mechanics of derive and what we do with it in Defaults (namely define scalaVersion, scalaBinaryVersion and, specifically, crossScalaVersions) this is a regression in sbt 0.13.16-M1.

steps

Given this build:

val t = project in file(".")
aggregateProjects(foo, bar)

      scalaVersion in ThisBuild := "2.11.11"
crossScalaVersions in ThisBuild := Seq("2.10.6", "2.11.11", "2.12.2")

val foo = project
val bar = project

problem

In sbt 0.13.16-M1 or sbt 0.13.16-RC1:

> show crossScalaVersions
[info] foo/*:crossScalaVersions
[info] 	List(2.11.11)
[info] bar/*:crossScalaVersions
[info] 	List(2.11.11)
[info] t/*:crossScalaVersions
[info] 	List(2.11.11)

expectation

How it used to work, such as in sbt 0.13.15:

> show crossScalaVersions
[info] foo/*:crossScalaVersions
[info] 	List(2.10.6, 2.11.11, 2.12.2)
[info] bar/*:crossScalaVersions
[info] 	List(2.10.6, 2.11.11, 2.12.2)
[info] t/*:crossScalaVersions
[info] 	List(2.10.6, 2.11.11, 2.12.2)

notes

The commit that folded sbt-cross-building into sbt introduced the project-scoped scalaVersion setting: https://github.com/sbt/sbt/commit/ff017eb475fbf18b8066125596bcd1a8cd8fb3ff#diff-6373e7f7122325e753b75fe1cc76ff5fR247

0reactions
eed3si9ncommented, Jul 25, 2017

This is a feature interaction between sbt version cross building and Scala version cross building.

Normally I try not to mess with existing globally-scoped keys, and I was aware that people often define scalaVersion in ThisBuild, so I did define a forwarder:

+    scalaVersion := {
+      val scalaV = scalaVersion.value
+      val sv = (sbtBinaryVersion in pluginCrossBuild).value
+      if (sbtPlugin.value) scalaVersionFromSbtBinaryVersion(sv)
+      else scalaV
+    },

I think I just need to do something similar with crossScalaVersions.

Note that recently merged https://github.com/sbt/sbt/pull/3356 re-injects scalaVersion at project-level on ^^. This might allow us to remove project-level scalaVersion initialization in Defaults, but I considering ^ compile etc crossScalaVersions forwarding still might be needed.

Read more comments on GitHub >

github_iconTop Results From Across the Web

What is the difference between ThisBuild and Global scopes?
Global is a scope that sets Zero to all axes: Zero / Zero / Zero . ... Zero whereas ThisBuild sets only the...
Read more >
sbt Reference Manual — Scopes
Scopes. This page describes scopes. It assumes you've read and understood the previous pages, build definition and task graph.
Read more >
Unification of sbt shell notation and build.sbt DSL - Tooling
I've long thought that sbt having two notations for setting keys, one for sbt shell and another for build.sbt made the tool harder...
Read more >
Making sense of SBT - Beyond the lines
The difference between the build.sbt and a scala file is that build.sbt ... tries the special scope ThisBuild , then the Global scope....
Read more >
The Scala Build Tool - It is all about Settings and Tasks - Binx
There's a special scope component ThisBuild (written as '{.}' in shell) for the subprojects axis only. Test extends Runtime, and Runtime extends ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found