Here's a minimal reproduction project:
project/build.properties
sbt.version=1.0.3
project/plugins.sbt:
addSbtPlugin("org.scala-js" % "sbt-scalajs" % "0.6.20")
libraryDependencies += "org.scala-js" %% "scalajs-env-selenium" % "0.2.0"
build.sbt:
import org.scalajs.jsenv.selenium.SeleniumJSEnv
import org.openqa.selenium.remote.DesiredCapabilities
inThisBuild(Seq(
name := "scalajsguava",
version := "1.0",
scalaVersion := "2.11.11",
))
val root = project.in(file(".")).enablePlugins(ScalaJSPlugin)
.settings(
libraryDependencies += "org.scalatest" %%% "scalatest" % "3.0.4",
jsEnv in Test := new SeleniumJSEnv(DesiredCapabilities.chrome),
)
When trying to run test from SBT I get:
[error] java.lang.NoSuchMethodError: com.google.common.base.Preconditions.checkState(ZLjava/lang/String;Ljava/lang/Object;)V
[error] at org.openqa.selenium.remote.server.DefaultDriverFactory.getProviderMatching(DefaultDriverFactory.java:50)
[error] at org.openqa.selenium.remote.server.DefaultDriverFactory.newInstance(DefaultDriverFactory.java:58)
[error] at org.scalajs.jsenv.selenium.SeleniumJSEnv.newDriver(SeleniumJSEnv.scala:43)
[error] at org.scalajs.jsenv.selenium.SeleniumJSEnv.$anonfun$jsRunner$1(SeleniumJSEnv.scala:29)
[error] at org.scalajs.jsenv.selenium.AbstractSeleniumJSRunner.setupRun(AbstractSeleniumJSRunner.scala:27)
[error] at org.scalajs.jsenv.selenium.SeleniumRunner.run(SeleniumRunner.scala:15)
[error] at org.scalajs.sbtplugin.FrameworkDetector.detect(FrameworkDetector.scala:71)
[error] at org.scalajs.sbtplugin.ScalaJSPluginInternal$.$anonfun$scalaJSTestFrameworkSettings$1(ScalaJSPluginInternal.scala:1004)
[error] at scala.Function1.$anonfun$compose$1(Function1.scala:44)
[error] at sbt.internal.util.$tilde$greater.$anonfun$$u2219$1(TypeFunctions.scala:42)
[error] at sbt.std.Transform$$anon$4.work(System.scala:64)
[error] at sbt.Execute.$anonfun$submit$2(Execute.scala:257)
[error] at sbt.internal.util.ErrorHandling$.wideConvert(ErrorHandling.scala:16)
[error] at sbt.Execute.work(Execute.scala:266)
[error] at sbt.Execute.$anonfun$submit$1(Execute.scala:257)
[error] at sbt.ConcurrentRestrictions$$anon$4.$anonfun$submitValid$1(ConcurrentRestrictions.scala:167)
[error] at sbt.CompletionService$$anon$2.call(CompletionService.scala:32)
[error] at java.util.concurrent.FutureTask.run(FutureTask.java:266)
[error] at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
[error] at java.util.concurrent.FutureTask.run(FutureTask.java:266)
[error] at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
[error] at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
[error] at java.lang.Thread.run(Thread.java:745)
This is caused by the fact that closure-compiler-java-6 artifact apparently has Guava embedded in itself with unchanged package name and it overrides the legitimate Guava 21.0 used by Selenium. So I can't even manually override Guava dependency using dependencyOverrides in project/plugins.sbt...
It doesn't have Guava AFAICT, but it seems to have some protobuf thing in there. Unfortunately this is also the case of the official closure-compiler artifact. It's not something specific to our fork.
You can force-override the dependency on closure-compiler by the official one released by Google, in which case you might get a newer version of the embedded things that would work in your case.
But other than that, I don't see how we can fix any of this on our end. :(
@sjrd When I look into the jar it pretty clearly has com.google.common package with many things normally found in Guava (although it doesn't have any actual guava package).
What's the difference between the ScalaJS fork and the official release? Is everything going to work when I override? Also, since there is a fork already, can't we fix it there by at least moving the embedded stuff to some other, non-conflicting package?
There should be a designated place in hell for people embedding libraries in their JARs without even changing the package.
The only difference between the Scala.js fork and the official release is that it supports Java 6. This meant changing some sources, e.g., not to relying on the diamond operator of Java 7. But otherwise we don't touch anything else.
Fixing this in our fork is not a reasonable solution, because in Scala.js 1.x we are going to switch back to the official versions, since Scala.js 1.x will only support sbt 1.x and therefore Java 8+ anyway.
We have the same problem in the build of Scala.js Selenium: https://github.com/scala-js/scala-js-env-selenium/blob/a2baa511f25d8bec70cd2ccb4671fec17e8a531d/build.sbt#L85-L88
So it is probably fine if you reorder the statements your project/plugins.sbt.
libraryDependencies += "org.scala-js" %% "scalajs-env-selenium" % "0.2.0"
addSbtPlugin("org.scala-js" % "sbt-scalajs" % "0.6.20")
Is this fixed? There is not really anything we can do, this is a closure-compiler issue...
Most helpful comment
We have the same problem in the build of Scala.js Selenium: https://github.com/scala-js/scala-js-env-selenium/blob/a2baa511f25d8bec70cd2ccb4671fec17e8a531d/build.sbt#L85-L88
So it is probably fine if you reorder the statements your
project/plugins.sbt.