Scala 2 artifact in Scala 3 project: conflicting cross-version suffixes - scala

I want to use Scala 2 library that wasn't migrated to Scala 3 yet in my Scala 3 project. When I add it as a dependency I get error Modules were resolved with conflicting cross-version suffixes. Is it possible to fix this?

You can exclude the 2.13 scala-collection-compat like this:
excludeDependencies += "org.scala-lang.modules" % "scala-collection-compat_2.13"

Related

zio-grpc with Scala 3 (2nd try)

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.
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:
https://mvnrepository.com/artifact/com.thesamet.scalapb/compilerplugin
https://mvnrepository.com/artifact/com.thesamet.scalapb.zio-grpc/zio-grpc-core
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.

scalafx in scala project intellij (unresolved dependencies path:)

i was compiling my scalafx code in intellij in a sbt file and they kept showing me this error, please help i tried everything but its still not working
[info] Updating
[info] Resolved dependencies
[warn]
[warn] Note: Unresolved dependencies path:
[error] stack trace is suppressed; run last update for the full output
[error] (update) sbt.librarymanagement.ResolveException: Error downloading org.scalafx:scalafx_2.13:8.0.192-R14
[error] Not found
[error] Not found
[error] not found: /Users/xxxxx/.ivy2/local/org.scalafx/scalafx_2.13/8.0.192-R14/ivys/ivy.xml
[error] not found: https://repo1.maven.org/maven2/org/scalafx/scalafx_2.13/8.0.192-R14/scalafx_2.13-8.0.192-R14.pom
this is my built.sbt
name := "practical4b"
version := "0.1"
scalaVersion := "2.13.1"
// https://mvnrepository.com/artifact/org.scalafx/scalafx
libraryDependencies += "org.scalafx"%%"scalafx"%"8.0.192-R14"
The problem here is that there is no release of ScalaFX 8/R14 that works with Scala 2.13.
Each Scala release, with the exception of bug-fix releases, has different binary compatibility requirements. So if you're using a Scala-built library with, say, Scala 2.13, you need the build of that library created for the same Scala version. Libraries created from Java code typically have binary compatibility with any version of Scala.
To determine which Scala versions are supported, they are listed in the column under Scala on Maven Central (the site linked to in your code above the libraryDependencies property):
You can resolve this problem either by switching to Scala 2.12, by changing the Scala version as follows:
scalaVersion := "2.12.12"
Or, you can use a more recent version of ScalaFX, that will work with Scala 2.13, by changing the library dependency as follows:
libraryDependencies += "org.scalafx" %% "scalafx" % "12.0.2-R18"
to use R18, or:
libraryDependencies += "org.scalafx" %% "scalafx" % "14-R19"
for R19.
A lot will depend upon which version of Java you are using. If you need to use Scala 2.13, with one of the more recent ScalaFX releases, I would recommend using Java 11 LTS. If you must use Java 8, then stay with the ScalaFX 8/R14 release and use Scala 2.12. Let me know if you have any questions.

Symbol 'type shapeless.LeftFolder' is missing from the classpath

Quick help out on this. During compilation I get the following set of errors ;
Error:(38, 21) Symbol 'type shapeless.HListerAux' is missing from the classpath.
This symbol is required by 'value spray.routing.directives.ParamDefMagnet2.hla'.
Make sure that type HListerAux is in your classpath and check for conflicting dependencies with `-Ylog-classpath`.
A full rebuild may help if 'ParamDefMagnet2.class' was compiled against an incompatible version of shapeless.
parameter('id) { id =>
Error:(38, 21) Symbol 'type shapeless.Poly.Case2' is missing from the classpath.
This symbol is required by 'method spray.routing.directives.ParamDefMagnet2.MapReduce.from'.
Make sure that type Case2 is in your classpath and check for conflicting dependencies with `-Ylog-classpath`.
A full rebuild may help if 'ParamDefMagnet2.class' was compiled against an incompatible version of shapeless.Poly.
parameter('id) { id =>
Error:(38, 21) Symbol 'type shapeless.PrependAux' is missing from the classpath.
This symbol is required by 'value spray.routing.directives.ParamDefMagnet2.MapReduce.ev'.
Make sure that type PrependAux is in your classpath and check for conflicting dependencies with `-Ylog-classpath`.
A full rebuild may help if 'ParamDefMagnet2.class' was compiled against an incompatible version of shapeless.
parameter('id) { id =>
Error:(38, 21) Symbol 'type shapeless.HListerAux' is missing from the classpath.
This symbol is required by 'value spray.routing.directives.ParamDefMagnet2.hla'.
Make sure that type HListerAux is in your classpath and check for conflicting dependencies with `-Ylog-classpath`.
A full rebuild may help if 'ParamDefMagnet2.class' was compiled against an incompatible version of shapeless.
parameter('id) { id =>
Although, in summary, the problem is with 'shapeless', a library which I have already included as a dependency as (with the resolvers),
resolvers ++= Seq(
Resolver.sonatypeRepo("releases"),
Resolver.sonatypeRepo("snapshots")
)
libraryDependencies ++= Seq(
"com.chuusai" %% "shapeless" % "2.3.2"
)
I would appreciate a suitable recommendation as a fix.
I know how to solve it, I met this problem before.
It is the problem of Shapeless Versions, read the following scentence carefully, and you will solve this problem.
Shapeless Versions
If you want to use shapeless as well as spray-routing in your application you need to select the version of spray(-routing) that was built against the shapeless release which you’d like to use.
For shapeless 1.2.4 you should use spray 1.1.4, 1.2.4 or 1.3.4 and the spray-routing module.
shapeless 2.0.0 is not supported any more.
For shapeless 2.3.0 you should use spray 1.3.4 (Scala 2.10 or Scala 2.11) and the spray-routing-shapeless23 module instead of spray-routing.
libraryDependencies ++= "io.spray" %% "spray-routing-shapeless23" % "1.3.4",

SBT: how to use scala 2.11 libraries in scala 2.12 project

I'm trying to upgrade my project to use scala 2.12
However, I use some libraries, which don't have 2.12 versions
(mongoquery-casbah, salat).
If I force to use 2.11 versions of those libraries
("com.github.salat" % "salat_2.11" % "1.10.0", "com.github.limansky" % "mongoquery-casbah_2.11" % "0.5"), I get error:
[error] Modules were resolved with conflicting cross-version suffixes in {file:/C:/work/GeneASS/}dao:
[error] org.scala-lang.modules:scala-parser-combinators _2.11, _2.12
How can I resolve this problem?
The only way is to recompile the library for scala 2.12. This of course requires that any transitive dependencies of the library are also 2.12 compatible.
Scala source code is mostly compatible between versions but compiled byte code is not so you need to build a seperate artifact for every scala version you want to support.

How can I use library which is built using 2.9.2 in project which is built using 2.10.1?

How can I use library build against 2.9.2 in project which is built using 2.10.1 ?
In particular I'm trying to use salat and get following exception
sbt.ResolveException: unresolved dependency: com.novus#salat_2.10;1.9.2-SNAPSHOT: not found
at sbt.IvyActions$.sbt$IvyActions$$resolve(IvyActions.scala:214)
at sbt.IvyActions$$anonfun$update$1.apply(IvyActions.scala:122)
at sbt.IvyActions$$anonfun$update$1.apply(IvyActions.scala:121)
at sbt.IvySbt$Module$$anonfun$withModule$1.apply(Ivy.scala:114)
at sbt.IvySbt$Module$$anonfun$withModule$1.apply(Ivy.scala:114)
at sbt.IvySbt$$anonfun$withIvy$1.apply(Ivy.scala:102)
at sbt.IvySbt.liftedTree1$1(Ivy.scala:49)
at sbt.IvySbt.action$1(Ivy.scala:49)
at sbt.IvySbt$$anon$3.call(Ivy.scala:58)
You can't. Major versions of Scala are binary incompatible.
You can. Just use OSGi. Use Scala 2.9.x with one bundle, use Scala 2.10.x with other. Work with multiple incompatible binary dependencies within single execution environment is one of the situations for which OSGi was created. Scala jar already packed as bundle. Everything ready.
You seem to be using the library version, built against 2.10. The artifact, you are using seems to be incorrect though. In your build.sbt try changing "com.novus" %% "salat" % "1.9.2-SNAPSHOT" to "com.novus" %% "salat-core" % "1.9.2-SNAPSHOT". Here's the full list of artifacts available for 2.10.
This works for me http://pastebin.com/yy6tGYDE
add "Sonatype OSS Snapshots" at "https://oss.sonatype.org/content/repositories/snapshots"
remove "org.mongodb" %% "casbah" % "2.6.0" possible conflict, salat 1.9.2-SNAPSHOT uses 2.5.0
change "com.novus" % "salat-core" % "1.9.2-SNAPSHOT" to "com.novus" %% "salat" % "1.9.2-SNAPSHOT"
You will have to recompile the library against scala 2.10 as the the scala-versions are binary incompatible with each major release. As from 2.9 to 2.10.