0

I am upgrading from Scala 2.13 -> 2.13.

After many changes my project compiles from IntelliJ, but sbt fails on launch (before any tasks are launched) with compilation errors due to one of my upgrade changes (Stream -> LazyList).

My build.sbt file references Scala 2.13.12 however it appears that when launching sbt some of the plugin source files are being compiled against Scala 2.12.

Could anyone advise how to control the version of Scala that these plugin source files are compiled with?

1 Answer 1

2

The key is to understand the difference between sbt proper build and sbt meta build projects. Conceptually they can be viewed as two different Scala projects with their own versions of Scala which might differ. For example, consider the following experiement:

Create a project from template:

➜  stackoverflow sbt new scala/scala-seed.g8
[info] welcome to sbt 1.4.7 (AdoptOpenJDK Java 1.8.0_275)
[info] loading settings for project global-plugins from idea.sbt,plugins.sbt ...
[info] loading global plugins from /Users/mario_galic/.sbt/1.0/plugins
[info] set current project to stackoverflow (in build file:/Users/mario_galic/code/stackoverflow/)
[info] set current project to stackoverflow (in build file:/Users/mario_galic/code/stackoverflow/)

A minimal Scala project.

name [Scala Seed Project]: proper-build-vs-meta-build-scala-version

Template applied in /Users/mario_galic/code/stackoverflow/./proper-build-vs-meta-build-scala-version

Now create a build.sbt file for the meta-build

➜  stackoverflow cd proper-build-vs-meta-build-scala-version
➜  proper-build-vs-meta-build-scala-version echo 'name := "meta-build-project"' > project/build.sbt

Now check the name and Scala version of the proper build

➜  proper-build-vs-meta-build-scala-version sbt
...
sbt:proper-build-vs-meta-build-scala-version> show name
[info] proper-build-vs-meta-build-scala-version
sbt:proper-build-vs-meta-build-scala-version> show scalaVersion
[info] 2.13.4

Now compare to the name and Scala version of the meta build

sbt:proper-build-vs-meta-build-scala-version> reload plugins
...
sbt:meta-build-project> show name
[info] meta-build-project
sbt:meta-build-project> show scalaVersion
[info] 2.12.12

Notice how meta-build is a separate project with its own scala version. The purpose of this project is to build your proper project. We say sbt is recursive.

Therefore migrating the proper project to Scala 2.13, does not affect the Scala version of the sbt plugins which are part of the meta-build.

Sign up to request clarification or add additional context in comments.

5 Comments

Is the meta project also responsible for the compilation of any locally built (i.e non imported) plugins? I believe this is what is happening because sbt itself is failing during the incremental compile stage.
@TerryDactyl Indeed your local custom made sbt plugins as well as downloaded sbt plugins must use the same scala version of the meta project.
So - from which file would I control the scala version?
@TereyDactyl project/build.sbt
Thanks for your help guys. It appears that the relevant file was located under project but not used by project however it was also used elsewhere and therefore compiled using the meta-build and proper-build versions (2.12 and 2.13). Problem now solved.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.