Scala 2.13, SBT: sbt compile uses wrong compiler version

Viewed 599

I am porting a small legacy library from scala 2.12 to scala 2.13. sbt version is 1.3.3. The project is flat and relatively simple. scalaVersion declared in the project is 2.13.1.

I am executing clean and compile tasks, and then publish to both local ivy and to the artifactory. The process seemingly goes fine and creates the artifact with the _2.13 suffix. When this binary gets executed against scala 2.13 runtime, it fails with MethodNotFound exception. Further introspection shows that the artifact was compiled for 2.12 but not for 2.13.

Does anybody have an idea why a different compiler version was used by sbt, and how to fix this problem?

1 Answers

Just had similar issue, sbt was compiling my project to the wrong Scala version, found this question without answers in google.

So, my problem was actually very simple. Turns out you need to start sbt in a project root directory (where build.sbt is located). I was running it from a directory where all my .scala files were located, so it haven't parsed build.sbt and compiled project using default Scala version (2.12 in my case).

Related