Skip to content
This repository has been archived by the owner on Jun 4, 2024. It is now read-only.

How do I use a different scala version? #237

Closed
tjarvstrand opened this issue Nov 13, 2019 · 7 comments
Closed

How do I use a different scala version? #237

tjarvstrand opened this issue Nov 13, 2019 · 7 comments

Comments

@tjarvstrand
Copy link

We are currently at 2.12.10 at the company where I work. Unfortunately it is very unobvious for someone new how to go about using this version instead of the default one. I'm sorry to say this part seems much more straight forward in bazelbuild/rules_scala.

@SrodriguezO
Copy link
Collaborator

This page explains how to configure a custom version: https://github.com/higherkindness/rules_scala/blob/master/docs/newdocs/scala_versions.md#specifying-the-scala-version-to-use

If you're fine using 2.12.8, you can simply use the default we provide by adding the following to your WORKSPACE:

bind(
    name = "default_scala",
    actual = "@rules_scala_annex//src/main/scala:zinc_2_12_8",
)

It's on the roadmap to provide more default versions, but we haven't gotten around to it (#204).

@SrodriguezO
Copy link
Collaborator

I'm going to go ahead and close this issue since there's already documentation and another open issue for simplifying things. Feel free to keep commenting if you need more help though :)

@tjarvstrand
Copy link
Author

Ehm, that was a bit quick. This is not a feature request but a question about how to solve a problem. I specifically asked Scala 2.12.10 in my question and just closing the issue with "here's how you use 2.12.8" is frankly pretty rude.

I have read the examples and I know how to point to Scala 2.12.8 but just changing the 8 to a 10 didn't work and I don't know where to go from there.

@SrodriguezO
Copy link
Collaborator

Hey @tjarvstrand my apologies, I was not trying to be rude. The link I shared explains how to use a different version of Scala. I simply suggested 2.12.8 because then you wouldn't have to do any boilerplate and a couple minor versions is oftentimes not problematic.

If you'd like an example of a specific Scala version being used, here is one were we use Scala 2.11.12. The relevant files are:

@tjarvstrand
Copy link
Author

Awesome thanks! I'll have a look at that!

It's just that if I'm going to sell the switch from sbt to the rest of my team it's going to be hard if we have to switch to an older Scala version

@SrodriguezO
Copy link
Collaborator

SrodriguezO commented Nov 14, 2019

Yeah that makes sense. Hopefully the example helps. I also updated the doc I sent you to explain how to specify the default scala configuration a little better.

@joprice
Copy link
Contributor

joprice commented Nov 28, 2019

Until I found the example above, I was unable to get scala 2.11 to work. I was seeing the following error:

  at scala.tools.util.PathResolverBase$Calculated$.javaBootClasspath(PathResolver.scala:277)
  at scala.tools.util.PathResolverBase$Calculated$.basis(PathResolver.scala:283)
  at scala.tools.util.PathResolverBase$Calculated$.containers$lzycompute(PathResolver.scala:293)
  at scala.tools.util.PathResolverBase$Calculated$.containers(PathResolver.scala:293)
  at scala.tools.util.PathResolverBase.containers(PathResolver.scala:309)
  at scala.tools.util.PathResolver.computeResult(PathResolver.scala:341)
  at scala.tools.util.PathResolver.computeResult(PathResolver.scala:332)
  at scala.tools.util.PathResolverBase.result(PathResolver.scala:314)
  at scala.tools.nsc.backend.JavaPlatform$class.classPath(JavaPlatform.scala:28)
  at scala.tools.nsc.Global$GlobalPlatform.classPath(Global.scala:115)
  at scala.tools.nsc.Global.scala$tools$nsc$Global$$recursiveClassPath(Global.scala:131)
  at scala.tools.nsc.Global$GlobalMirror.rootLoader(Global.scala:64)
  at scala.reflect.internal.Mirrors$Roots$RootClass.<init>(Mirrors.scala:307)
  at scala.reflect.internal.Mirrors$Roots.RootClass$lzycompute(Mirrors.scala:321)
  at scala.reflect.internal.Mirrors$Roots.RootClass(Mirrors.scala:321)
  at scala.reflect.internal.Mirrors$Roots$EmptyPackageClass.<init>(Mirrors.scala:330)
  at scala.reflect.internal.Mirrors$Roots.EmptyPackageClass$lzycompute(Mirrors.scala:336)
  at scala.reflect.internal.Mirrors$Roots.EmptyPackageClass(Mirrors.scala:336)
  at scala.reflect.internal.Mirrors$Roots.EmptyPackageClass(Mirrors.scala:276)
  at scala.reflect.internal.Mirrors$RootsBase.init(Mirrors.scala:250)
  at scala.tools.nsc.Global.rootMirror$lzycompute(Global.scala:73)
  at scala.tools.nsc.Global.rootMirror(Global.scala:71)
  at scala.tools.nsc.Global.rootMirror(Global.scala:39)

The key was to configure the jdk here https://github.com/lucidsoftware/play_routes_compiler_cli/blob/3bfd27c266c4958fd62ecfef6434bac3cc0bf0ba/BUILD, https://github.com/lucidsoftware/play_routes_compiler_cli/blob/3bfd27c266c4958fd62ecfef6434bac3cc0bf0ba/WORKSPACE#L42, and https://github.com/lucidsoftware/play_routes_compiler_cli/blob/3bfd27c266c4958fd62ecfef6434bac3cc0bf0ba/.bazelrc#L3

Ultimately, I'm trying to figure out what it takes to support 2.11 and 2.12 in one repo, and whether it's worth it just to push toward 2.12 instead. If you are fine with being locked on jdk 8, then this setup should work for both. Otherwise, you would want to vary the jdk based on scala version, and I don't know enough bazel yet to know if that's possible.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants