Reputation: 4836
I have a Spark project in Scala in which I'm trying to use google-cloud-storage
dependency. Following are the dependencies added in by build.sbt
val sparkVersion = "2.2.0"
"org.apache.spark" %% "spark-core" % sparkVersion % "provided",
"org.apache.spark" %% "spark-sql" % sparkVersion % "provided",
"com.google.cloud" % "google-cloud-storage" % "1.55.0",
"com.typesafe" % "config" % "1.3.1"
Now when I build the jar and run it I get following Exception.
Exception in thread "main" java.lang.NoSuchMethodError: com.google.common.base.Preconditions.checkArgument(ZLjava/lang/String;Ljava/lang/Object;)V
Upon googling I found out that it is caused because of multiple versions of Guava
on my classpath.
In an attempt to resolve the issue I excluded Guava
from google-cloud-storage
dependency.
"com.google.cloud" % "google-cloud-storage" % "1.55.0" exclude("com.google.guava", "guava"),
But then I got following error:
Exception in thread "main" java.lang.NoClassDefFoundError: com/google/cloud/storage/StorageOptions
This error means that now there was no Guava
jars at classpath.
My question is how is that possible before excluding guava I was getting error due to multiple version at classpath, how come I get no guava jars found error when I exclude one version of it.
How to resolve this error.
Upvotes: 1
Views: 1338
Reputation: 14803
You can try to add the guava
dependency as an explicit dependency:
libraryDependencies += "com.google.guava" % "guava" % "newest_version"
To figure out the newest version you can use this Plugin: sbt-dependency-graph
Or check the eviction warnings
in the SBT console.
Upvotes: 2