0

Does anyone have a bare-bones zio-grpc server, with codegen in the project also, working with Scala 3?

I started with the HelloWorld project from their repo and attempted to get it to build with scalaVersion := "3.1.0"

Here is the relevant section in plugins.sbt:

libraryDependencies ++= Seq(
  "com.thesamet.scalapb.zio-grpc" % "zio-grpc-codegen_2.13" % zioGrpcVersion,
  "com.thesamet.scalapb" % "compilerplugin_2.13" % "0.11.1"
)

excludeDependencies ++= Seq(
  ExclusionRule("org.scala-lang.modules", "scala-collection-compat_2.12"),
  ExclusionRule("com.thesamet.scalapb", "protoc-bridge_2.12")
)

and in build.sbt:

libraryDependencies ++= Seq(
  "io.grpc" % "grpc-netty" % grpcVersion,
  "com.thesamet.scalapb" % "scalapb-runtime-grpc_2.13" % scalapb.compiler.Version.scalapbVersion
)

excludeDependencies ++= Seq(
  ExclusionRule("org.scala-lang.modules", "scala-collection-compat_2.12"),
  ExclusionRule("com.thesamet.scalapb", "protoc-bridge_2.12")
)

Since Scala 3 can use 2.13 libraries, that's what I'm doing. (Of the three zio-grpc-related libs, one, zio-grpc-codegen, does not have a Scala 3 version, so 2.13 must be used at least for that one.)

I get this error from sbt with the versions as above:

java.lang.NoSuchMethodError: scala.package$.Seq()Lscala/collection/immutable/Seq$; at protocbridge.gens$.java(gens.scala:17) at protocbridge.gens$.(gens.scala:11)

If I remove either of the scala-collection-compat exclusions, we get

[error] Modules were resolved with conflicting cross-version suffixes in ProjectRef(uri("file:/Users/xxx/dev/zio-grpc/examples/helloworld/project/"), "helloworld-build"): [error] com.thesamet.scalapb:protoc-bridge _2.12, _2.13 [error] com.thesamet.scalapb:compilerplugin _3, _2.13

In short, I cannot find any permutation of Scala 2.13/3 versions of zio-grpc-codegen, compilerplugin_3, and scalapb-runtime-grpc that will not give some sbt conflicting cross-version suffix error.

  • Did you try to remove exclusions in `plugins.sbt` and use automatic Scala version? `libraryDependencies ++= Seq( "com.thesamet.scalapb.zio-grpc" %% "zio-grpc-codegen" % zioGrpcVersion, "com.thesamet.scalapb" %% "compilerplugin" % "0.11.1" )`. What does it give you? – Gaël J Jan 10 '22 at 20:03
  • This won't work because one of the three libs (codegen) doesn't have a Scala 3 version. At the least one must use 2.13 for that. Exclusions were added as necessary only. I tried pretty much every combination. The NoSuchMethodError from protocbridge is the "best" result I got as at least sbt doesn't die from cross-version collisions. – Bender Rodriguez Jan 10 '22 at 20:31
  • But did you try? Which error did you get? – Gaël J Jan 10 '22 at 21:15

2 Answers2

0

TL;DR: this is not possible yet as some of the code you are using rely on macros and is not yet published for Scala3.


SBT plugins runs with Scala 2.12 no matter which Scala version is used in your project, thus you don't have to try to use plugins with _2.13 or _3 suffix, just use the regular syntax that will actually pick _2.12 artifacts.

That is, in plugins.sbt:

libraryDependencies ++= Seq(
  "com.thesamet.scalapb.zio-grpc" %% "zio-grpc-codegen" % zioGrpcVersion,
  "com.thesamet.scalapb" %% "compilerplugin" % "0.11.8"
)

(No need for any exclusion).

You can confirm this by looking at sbt logs and you should see that it downloads plugins for version 2.12 of Scala:

...
https://somerepository.com/com/thesamet/scalapb/zio-grpc/zio-grpc-codegen_2.12/0.5.1/zio-grpc-codegen_2.12-0.5.1.pom
https://somerepository.com/com/thesamet/scalapb/compilerplugin_2.12/0.11.8/compilerplugin_2.12-0.11.8.pom
...

Once you do that, you'll get an error as following dependencies do not exist:

  • com.thesamet.scalapb:scalapb-runtime_3:0.11.1
  • com.thesamet.scalapb:scalapb-runtime-grpc_3:0.11.1
  • com.thesamet.scalapb.zio-grpc:zio-grpc-core_3:0.5.0

For the 1st and 2nd, you just have to update the compilerplugin version to 0.11.8 as I did already above (the compilerplugin version is used for the main dependency scalapb-runtime-grpc).

For the 3rd, unfortunately it's not published yet for Scala 3. One attempt is to force the _2.13 version for this one with something like that in the build.sbt:

libraryDependencies += ("com.thesamet.scalapb.zio-grpc" %% "zio-grpc-core" % "0.5.1") cross CrossVersion.for3Use2_13

excludeDependencies += "com.thesamet.scalapb.zio-grpc" % "zio-grpc-core_3"

But this doesn't compile with some errors related to macros, and that is something that is not compatible between Scala 2.13 and 3. You cannot workaround that.


Remember you can check available versions of a lib for a Scala version on Maven central:

Gaël J
  • 11,274
  • 4
  • 17
  • 32
  • We'd concluded the best route is to gen code separately, keeping that part (including the SBT plugin) out of the project. A Scala 3 server can be run with that code with no issues. Thanks for this great, detailed information. – Bender Rodriguez Jan 11 '22 at 17:34
0

I haven't released zio-grpc for Scala 3 as some tests related to Has were failing and were tricky to fix. At the same ZIO 2 is coming out and deprecated Has. There's a version of zio-grpc with ZIO 2 and Scala 3 support coming soon.

thesamet
  • 6,382
  • 2
  • 31
  • 42