Can not resolve dependencies after upgrading to version 2.12 - scala

Because I had some dependency issues, I decided to upgrade the Scala installation on my computer to version 2.12.0-M3. I also ran sbt -v, after which many packages were downloaded.
However, when I try to refresh the following build.sbt file
name := """ScalaWeb"""
version := "1.0-SNAPSHOT"
lazy val root = (project in file(".")).enablePlugins(PlayScala)
scalaVersion := "2.12.0-M3"
libraryDependencies ++= Seq(
jdbc,
cache,
ws,
specs2 % Test,
"org.sorm-framework" % "sorm" % "0.3.18"
)
resolvers += "scalaz-bintray" at "http://dl.bintray.com/scalaz/releases"
// Play provides two styles of routers, one expects its actions to be injected, the
// other, legacy style, accesses its actions statically.
routesGenerator := InjectedRoutesGenerator
scalacOptions += "-Ylog-classpath"
I get the following errors:
Error:Unresolved dependencies:
com.typesafe.play#twirl-api_2.12.0-M3;1.1.1: not found
com.typesafe.play#play-server_2.12.0-M3;2.4.6: not found
com.typesafe.play#play-netty-server_2.12.0-M3;2.4.6: not found
com.typesafe.play#play-jdbc_2.12.0-M3;2.4.6: not found
com.typesafe.play#play-cache_2.12.0-M3;2.4.6: not found
com.typesafe.play#play-ws_2.12.0-M3;2.4.6: not found
com.typesafe.play#play-test_2.12.0-M3;2.4.6: not found
com.typesafe.play#play-specs2_2.12.0-M3;2.4.6: not found
com.typesafe.play#play-omnidoc_2.12.0-M3;2.4.6: not found
Version 2-12.0-M3 appeared in October 2015. It seems doubtful that all these packages are still incompatible.
How can I solve this issue?
PS
I was unable to use scala version 2.11.7 because I have the dependency
"org.sorm-framework" % "sorm" % "0.3.18"
Which, because of its dependencies, produces this issues:
[error] org.scala-lang.modules:scala-xml _2.11, _2.12.0-M3
[error] org.scala-lang.modules:scala-parser-combinators _2.11, _2.12.0-M3

It seems the SORMS author is defining Scala library dependencies wrongly. As a result you have horrible transitive Scala dependencies for versions like [2.10,2.12), so it will pick whatever latest Scala version was published, including in your case 2.12.0-M3 apparently.
Looking at the POM of 0.3.18 and the POM of 0.3.19, it seems that the later version uses (still wrong!!) [2.10,2.11.999).
So I think you can solve your issue using these settings:
scalaVersion := "2.11.7"
libraryDependencies += "org.sorm-framework" % "sorm" % "0.3.19"
If not, you will have to exclude the problematic transitive dependencies from SORM.
Update: The bug report also hints that the dependency you need to exclude is actually embrace. For example, using the sbt-dependency-graph plugin, running sbt dependency-dot and inspecting the result I find:
"com.github.nikita-volkov:embrace:0.1.4" -> "org.scala-lang:scala-compiler:2.12.0-M3"
which seems to be the origin of the evil.
Instead of excluding, I am now forcing a version of Scala:
scalaVersion := "2.11.7"
libraryDependencies ++= Seq(
"org.sorm-framework" % "sorm" % "0.3.19",
"org.scala-lang" % "scala-compiler" % scalaVersion.value force() // !!
)
This worked for me.

Related

SBT binary incompatible issue scala-parser-combinators

I am new to the Scala env and trying to build a test project using play with 'scalikejdbc' for SQL integration. Here is my build.sbt following the documents at http://scalikejdbc.org/documentation/playframework-support.html
name := """run"""
organization := "com.example"
version := "1.0-SNAPSHOT"
lazy val root = (project in file(".")).enablePlugins(PlayScala)
scalaVersion := "2.13.10"
libraryDependencies ++= Seq(
guice,
"org.scalatestplus.play" %% "scalatestplus-play" % "5.0.0" % Test,
"com.h2database" % "h2" % "1.4.200", // your jdbc driver here
"org.scalikejdbc" %% "scalikejdbc" % "4.0.0",
"org.scalikejdbc" %% "scalikejdbc-config" % "4.0.0",
"org.scalikejdbc" %% "scalikejdbc-play-initializer" % "2.8.0-scalikejdbc-3.5",
"com.typesafe.play" %% "play-ws" % "2.3.1"
)
dependencyOverrides += "org.fluentlenium" % "fluentlenium-core" % "0.10.3"
// Adds additional packages into Twirl
//TwirlKeys.templateImports += "com.example.controllers._"
// Adds additional packages into conf/routes
// play.sbt.routes.RoutesKeys.routesImport += "com.example.binders._"
I have also aded the below on plugins.sbt
resolvers += Resolver.url("SBT Plugins", url("https://repo.scala-sbt.org/scalasbt/sbt-plugin-releases/"))(Resolver.ivyStylePatterns)
However while trying to update the application before running i am getting the below issue
[error] (update) found version conflict(s) in library dependencies; some are suspected to be binary incompatible:
[error]
[error] * org.scala-lang.modules:scala-parser-combinators_2.13:2.1.0 (early-semver) is selected over {1.1.2}
[error] +- org.scalikejdbc:scalikejdbc-core_2.13:4.0.0 (depends on 2.1.0)
[error] +- com.typesafe.play:play_2.13:2.8.18 (depends on 1.1.2)
[error] +- com.typesafe:ssl-config-core_2.13:0.4.3 (depends on 1.1.2)
[error]
following are relevant versions :
sbt script version: 1.8.0
play version :2.8.18
Scala code runner version 3.2.1 but using as scalaVersion := "2.13.10" in sbt.
version conflict(s) in library dependencies; some are suspected to be binary incompatible
This means that you have at least two dependencies that are needing a 3rd one but they need 2 different versions which are supposed to be incompatible.
As only one can be included and used for your code, SBT is telling you: "I am going to pick one version but there are risks that this version won't work as you might have code that rely on the other version and this might be incompatible".
You have 2 options:
force a version (for scala-parser-combinators) with dependencyOverrides for instance if you know that actually there's no incompatibility, or at least on the way you use the libraries
upgrade or downgrade the libraries (scalikejdbc or play) so that all libraries depend on the same version of the conflicting one (scala-parser-combinators).
In this case, I would downgrade scalikejdbc because there's no newer play version (as of today)

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.

Scala libraries incompatibility

akka-actor_2.13-2.5.23.jar of play-scala-seed build path is cross-compiled with an incompatible version of Scala (2.13.0). In case this report is mistaken, this check can be disabled in the compiler preference page.
I have many errors of this type in my scala project. How do I resolve such errors?
I am using Scala IDE.
build.sbt:
name := """play-scala-seed"""
organization := "com.example"
version := "1.0-SNAPSHOT"
lazy val root = (project in file(".")).enablePlugins(PlayScala)
scalaVersion := "2.13.0"
libraryDependencies += guice
libraryDependencies += "org.scalatestplus.play" %% "scalatestplus-play" % "4.0.3" % Test
// Adds additional packages into Twirl
//TwirlKeys.templateImports += "com.example.controllers._"
// Adds additional packages into conf/routes
// play.sbt.routes.RoutesKeys.routesImport += "com.example.binders._"
I guess I need to change Scala installation to 2.13, right? ( I am referring to the Scala installation option that shows up in the project properties after right clicking on the project in the IDE )
But, the only options available in the dropdown are 2.10,2.11 and 2.12. How do I add 2.13 into my IDE?
The solutions in similar questions did not work for me.

How to resolve this exception invalid dependency detected while loading class file 'SprayJsonSupport.class'

I'am using
version := "1.0"
scalaVersion := "2.11.8"
scalacOptions := Seq("-unchecked", "-deprecation", "-encoding", "utf8")
libraryDependencies ++= {
val akkaV = "2.4.18"
val scalaTestV = "2.2.6"
val akkaHttpV = "10.0.10"
}
I tried to run my test cases but it's showing error like this
Error:scalac: missing or invalid dependency detected while loading class file 'SprayJsonSupport.class'.
Could not access type FromByteStringUnmarshaller in package akka.http.scaladsl.unmarshalling.package,
because it (or its dependencies) are missing. Check your build definition for
missing or conflicting dependencies. (Re-run with `-Ylog-classpath` to see the problematic classpath.)
A full rebuild may help if 'SprayJsonSupport.class' was compiled against an incompatible version of akka.http.scaladsl.unmarshalling.package.
How can I resolve this can suggest here, please.
Thank you.
Please add the latest spray Json dependency, also update your Akka-test kit version, sbt and scala version.
As you are using marshaller and unmarshaller
To convert your case class into json and vice versa.
I think it should solve your problem.
libraryDependencies += "io.spray" %% "spray-json" % "1.3.1"
Add this in your dependency it’s compatible with Scala 2.11.x
But I would suggest you to update all your dependency with the new ones.

Can't install Scaladoc with SBT and Intellij

I am new to scala and am currently trying to setup IntelliJ IDEA 13.1 with the Scala plugin. It has support for SBT. I have simply followed the basic tutorial for creating a new project for SBT here: http://confluence.jetbrains.com/display/IntelliJIDEA/Getting+Started+with+SBT
Currently my build.sbt file is:
name := "scalasandpit"
version := "1.0"
scalaVersion := "2.10"
libraryDependencies += "org.scalatest" % "scalatest_2.10" % "2.1.0" % "test"
autoAPIMappings := true
This pulls down various jar binaries, but no sources and no javadoc. I wondered if there is a way to have both sources and javadoc work with IntelliJ and SBT. I think I'm missing something.
There seem to be two issues: getting sbt to pull down sources and docs, and then getting Idea to show them to you. To solve the former problem see the sbt documentation -- about half way down there's a section called "Download Sources" which tells you what to add to your build.sbt:
libraryDependencies +=
"org.scalatest" % "scalatest_2.10" % "2.1.0" % "test" withSources() withJavadoc()