jsevellec / cassandra-unit

Utility tool to load Data into Cassandra to help you writing good isolated JUnit Test into your application
GNU Lesser General Public License v3.0
424 stars 1 forks source link

“NoSuchMethodErrors” due to multiple versions of io.dropwizard.metrics:metrics-core:jar #314

Open Bing-ok opened 4 years ago

Bing-ok commented 4 years ago

Issue description

Hi, there are multiple versions of io.dropwizard.metrics:metrics-core in cassandra-unit-master\cassandra-unit. As shown in the following dependency tree, according to Maven's “nearest wins” strategy, only io.dropwizard.metrics:metrics-core:3.1.5 can be loaded, io.dropwizard.metrics:metrics-core:3.1.0 and io.dropwizard.metrics:metrics-core:4.0.5 will be shadowed.

However, several methods defined in shadowed version io.dropwizard.metrics:metrics-core:4.0.5 is referenced by client project via com.datastax.oss:java-driver-core:4.3.1, but missing in the actually loaded version io.dropwizard.metrics:metrics-core:3.1.5.

For instance, the following missing methods(defined in io.dropwizard.metrics:metrics-core:4.0.5) is actually referenced by cassandra-unit-master\cassandra-unit, which will introduce a runtime error(i.e., "NoSuchMethodErrors") into cassandra-unit-master\cassandra-unit.

1. com.codahale.metrics.MetricRegistry: com.codahale.metrics.Gauge gauge(java.lang.String,com.codahale.metrics.MetricRegistry$MetricSupplier) is invoked by cassandra-unit-master\cassandra-unit via the following path:


paths------
<org.cassandraunit.utils.EmbeddedCassandraServerHelper: void startEmbeddedCassandra(java.io.File,long)> cassandra-unit-master\cassandra-unit\target\classes
<org.cassandraunit.utils.EmbeddedCassandraServerHelper: void startEmbeddedCassandra(java.io.File,java.lang.String,long)> cassandra-unit-master\cassandra-unit\target\classes
<com.datastax.oss.driver.internal.core.session.DefaultSession$SingleThreaded$closePolicies__306: void run()> 
<com.datastax.oss.driver.internal.core.session.DefaultSession$SingleThreaded: void closePolicies()> Repositories\com\datastax\oss\java-driver-core\4.3.1\java-driver-core-4.3.1.jar
<com.datastax.oss.driver.internal.core.context.DefaultDriverContext$buildMetricsFactory__120: java.lang.Object get()> 
<com.datastax.oss.driver.internal.core.context.DefaultDriverContext: com.datastax.oss.driver.internal.core.metrics.MetricsFactory buildMetricsFactory()> Repositories\com\datastax\oss\java-driver-core\4.3.1\java-driver-core-4.3.1.jar
<com.datastax.oss.driver.internal.core.metrics.DropwizardMetricsFactory: void (com.datastax.oss.driver.internal.core.context.InternalDriverContext)> Repositories\com\datastax\oss\java-driver-core\4.3.1\java-driver-core-4.3.1.jar
<com.datastax.oss.driver.internal.core.metrics.DropwizardSessionMetricUpdater: void (java.util.Set,com.codahale.metrics.MetricRegistry,com.datastax.oss.driver.internal.core.context.InternalDriverContext)> Repositories\com\datastax\oss\java-driver-core\4.3.1\java-driver-core-4.3.1.jar
<com.codahale.metrics.MetricRegistry: com.codahale.metrics.Gauge gauge(java.lang.String,com.codahale.metrics.MetricRegistry$MetricSupplier)>

2. com.codahale.metrics.MetricRegistry: com.codahale.metrics.Timer timer(java.lang.String,com.codahale.metrics.MetricRegistry$MetricSupplier) is invoked by cassandra-unit-master\cassandra-unit via the following path:


paths------
<org.cassandraunit.utils.EmbeddedCassandraServerHelper: void startEmbeddedCassandra(java.io.File,java.lang.String,long)> cassandra-unit-master\cassandra-unit\target\classes
<com.datastax.oss.driver.internal.core.session.DefaultSession$SingleThreaded$closePolicies__306: void run()>  
<com.datastax.oss.driver.internal.core.session.DefaultSession$SingleThreaded: void closePolicies()> Repositories\com\datastax\oss\java-driver-core\4.3.1\java-driver-core-4.3.1.jar
<com.datastax.oss.driver.internal.core.context.DefaultDriverContext$buildMetricsFactory__120: java.lang.Object get()> 
<com.datastax.oss.driver.internal.core.context.DefaultDriverContext: com.datastax.oss.driver.internal.core.metrics.MetricsFactory buildMetricsFactory()> Repositories\com\datastax\oss\java-driver-core\4.3.1\java-driver-core-4.3.1.jar
<com.datastax.oss.driver.internal.core.metrics.DropwizardMetricsFactory: void init (com.datastax.oss.driver.internal.core.context.InternalDriverContext)> Repositories\com\datastax\oss\java-driver-core\4.3.1\java-driver-core-4.3.1.jar
<com.datastax.oss.driver.internal.core.metrics.DropwizardSessionMetricUpdater: void init (java.util.Set,com.codahale.metrics.MetricRegistry,com.datastax.oss.driver.internal.core.context.InternalDriverContext)> Repositories\com\datastax\oss\java-driver-core\4.3.1\java-driver-core-4.3.1.jar
<com.datastax.oss.driver.internal.core.metrics.DropwizardMetricUpdater: void initializeHdrTimer(java.lang.Object,com.datastax.oss.driver.api.core.config.DriverExecutionProfile,com.datastax.oss.driver.api.core.config.DriverOption,com.datastax.oss.driver.api.core.config.DriverOption,com.datastax.oss.driver.api.core.config.DriverOption)> Repositories\com\datastax\oss\java-driver-core\4.3.1\java-driver-core-4.3.1.jar
<com.codahale.metrics.MetricRegistry: com.codahale.metrics.Timer timer(java.lang.String,com.codahale.metrics.MetricRegistry$MetricSupplier)>

Suggested fixing solutions:

  1. Dieclare a direct dependency io.dropwizard.metrics:metrics-core:4.0.5 in the pom file of cassandra-unit-master\cassandra-unit to upgrade version from 3.1.5 to 4.0.5.
  2. Use configuration attribute <dependencyManagement> to unify the version of library io.dropwizard.metrics:metrics-core to be 4.0.5 in cassandra-unit-master\cassandra-unit's pom file.
  3. Use <exclude> to exclude io.dropwizard.metrics:metrics-core:3.1.5 from the dependency tree, so version 4.0.5 will be loaded.

Please let me know which solution do you prefer? I can submit a PR to fix it.

Thank you very much for your attention. Best regards,

Dependency tree----


[INFO] org.cassandraunit:cassandra-unit:jar:4.3.1.1-SNAPSHOT
[INFO] +- org.apache.cassandra:cassandra-all:jar:3.11.5:compile
[INFO] |  +- io.dropwizard.metrics:metrics-core:jar:3.1.5:compile
[INFO] |  +- io.dropwizard.metrics:metrics-jvm:jar:3.1.5:compile
[INFO] |  |  \- (io.dropwizard.metrics:metrics-core:jar:3.1.5:compile - omitted for duplicate)
[INFO] |  \- com.addthis.metrics:reporter-config3:jar:3.0.3:compile
[INFO] |     \- (io.dropwizard.metrics:metrics-core:jar:3.1.0:compile - omitted for conflict with 3.1.5)
[INFO] \- com.datastax.oss:java-driver-core:jar:4.3.1:compile
[INFO]    \- (io.dropwizard.metrics:metrics-core:jar:4.0.5:compile - omitted for conflict with 3.1.5)
Bing-ok commented 4 years ago

Could you help me review this issue? 👍 Thanks! @jsevellec

sean-heller commented 4 years ago

i'm seeing something similar in my projects, would love an update on this! thanks!

wakingrufus commented 3 years ago

I have solved this problem for myself by adding io.dropwizard.metrics to the list of shaded (and relocated) dependencies in cassandra-unit-shaded