codingwell / scala-guice

Scala extensions for Google Guice
Apache License 2.0
341 stars 44 forks source link

Update guice dependency version to 5.1.0 #102

Closed heuermh closed 2 years ago

heuermh commented 2 years ago

Hello! I'm having trouble with runtime classpath conflicts with Guava and Guice versions

scala> val bc = BiojavaAdamContext(sc)
java.lang.NoSuchMethodError:
'com.google.common.base.Stopwatch com.google.common.base.Stopwatch.createUnstarted()'
  at com.google.inject.internal.InternalInjectorCreator.<init>(InternalInjectorCreator.java:64)
  at com.google.inject.Guice.createInjector(Guice.java:87)
  at com.google.inject.Guice.createInjector(Guice.java:69)
  at com.google.inject.Guice.createInjector(Guice.java:59)
  at org.biojava.nbio.adam.BiojavaAdamContext$.apply(BiojavaAdamContext.scala:93)
  ... 47 elided

and haven't been able to determine the right combination of shading & relocating to make it work

java.lang.NoClassDefFoundError:
org/biojava/nbio/adam/shaded/net/codingwell/scalaguice/InjectorExtensions$ScalaInjector$
  at org.biojava.nbio.adam.BiojavaAdamContext$.apply(BiojavaAdamContext.scala:94)
  ... 47 elided
Caused by: java.lang.ClassNotFoundException:
org.biojava.nbio.adam.shaded.net.codingwell.scalaguice.InjectorExtensions$ScalaInjector$
  at java.base/java.net.URLClassLoader.findClass(URLClassLoader.java:476)
  at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:589)
  at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:522)
  ... 48 more

Hopefully updating scala-guice to use version 5.1.0 of Guice will alleviate this issue. Thank you!

tsuckow commented 2 years ago

5.1.0 should be live on maven central shortly.

But I doubt it will help since both 5.0.1 and 5.1.0 use com.google.guava % guava % 30.1-jre

Wish I had some tips on shading, but I don't really do Java dev these days. Maybe https://bryantsai.com/how-to-resolve-dependency-conflict-out-of-your-control-e75ace79e54f is of some help.

heuermh commented 2 years ago

Thank you @tsuckow! Will give it a try.

It appears that relocation via the Maven Shade plugin isn't able to handle the Scala classes correctly or perhaps some reflection is going wrong. I wish I had a simpler use case that would demonstrate the problem, unfortunately I run into this with an library that uses guice on its own on top of another one that uses scala-guice and the whole stack runs on Apache Spark.