Why do I get conflicting cross-version in sbt on one environment but not another?
Asked Answered
A

1

7

I have an sbt project with these dependencies:

libraryDependencies ++= Seq(
  "org.scalatra"           %% "scalatra"          % ScalatraVersion,
  "org.scalatra"           %% "scalatra-scalate"  % ScalatraVersion,
  "org.scalatra"           %% "scalatra-specs2"   % ScalatraVersion   % "test",
  "ch.qos.logback"         %  "logback-classic"   % "1.1.2"           % "runtime",
  "org.eclipse.jetty"      %  "jetty-webapp"      % "9.1.5.v20140505" % "container",
  "org.eclipse.jetty"      %  "jetty-plus"        % "9.1.5.v20140505" % "container",
  "javax.servlet"          %  "javax.servlet-api" % "3.1.0",
  "org.sorm-framework"     %  "sorm"              % "0.3.18",
  "com.h2database"         %  "h2"                % "1.4.187",
  "org.fusesource.scalamd" %  "scalamd_2.10"      % "1.6"
)

On one machine, I can run ./sbt without issue; on the other, I get

[error] Modules were resolved with conflicting cross-version suffixes in {file:/C:/dev/scalaspace/game-tracker/}game-tracker:
[error]    org.scala-lang.modules:scala-xml _2.11, _2.12.0-M1
[error]    org.scala-lang.modules:scala-parser-combinators _2.11, _2.12.0-M1

I've already isolated the problem and the fix. Sorm depends on the 2.12.0-M1 compiler:

[info]   +-org.sorm-framework:sorm:0.3.18 [S]
[info]     +-com.github.nikita-volkov:embrace:0.1.4 [S]
[info]     | +-org.scala-lang:scala-compiler:2.12.0-M1 [S]
[info]     |   +-org.scala-lang.modules:scala-parser-combinators_2.12.0-M1:1.0.4 [S]
[info]     |   +-org.scala-lang.modules:scala-xml_2.12.0-M1:1.0.4 [S]
[info]     |   +-org.scala-lang:scala-reflect:2.11.0 [S] (evicted by: 2.11.6)
[info]     |   +-org.scala-lang:scala-reflect:2.11.6 [S]
[info]     |   +-org.scala-lang:scala-reflect:2.12.0-M1 (evicted by: 2.11.0)

I can make the project build in both locations by adding exclude("org.scala-lang","scala-compiler") to the sorm dependency. But why is the behavior inconsistent? Both environments are using the same version of sbt (0.13.8) and scala (2.11.6). What's different?

Arhat answered 6/5, 2015 at 21:51 Comment(0)
G
12

Given the pom for com.github.nikita-volkov:embrace, I'm guessing it's due to the use of version ranges combined with caching:

<dependency>
  <groupId>org.scala-lang</groupId>
  <artifactId>scala-compiler</artifactId>
  <version>[2.10,3)</version>
  <scope>compile</scope>
</dependency>

Particularly given that Scala 2.12.0-M1 was release yesterday:


To fix the inconsistency you want to clear your ivy cache:

rm -r ~/.ivy2/cache

However you also want to fix the version of scala-compiler use, and you want it to match your configured scalaVersion:

dependencyOverrides += "org.scala-lang" % "scala-compiler" % scalaVersion.value

See more details in the Overriding a version section of the Library Management docs.

Grained answered 6/5, 2015 at 22:25 Comment(2)
Ah, you are correct. Clearing my ivy cache caused the old environment to break in the same way. What's the best way to force the version of scala-compiler? I added "org.scala-lang" % "scala-compiler" % ScalaVersion to the top of my dependencies, but still get the conflicting cross version error.Arhat
You want to use dependencyOverrides += "org.scala-lang" % "scala-compiler" % scalaVersion.value. There's more info about it also in the docs: scala-sbt.org/release/docs/…Grained

© 2022 - 2024 — McMap. All rights reserved.