xvik / dropwizard-guicey

Dropwizard guice integration
http://xvik.github.io/dropwizard-guicey/
MIT License
232 stars 49 forks source link

Updated dependencies to Dropwizard Guicey » 6.2.1 breaks our integration tests #390

Closed jdettmannnava closed 4 months ago

jdettmannnava commented 4 months ago

We use dropwizard guicey in our java application, and it works great! Unfortunately, our integration tests began failing this week. We have a custom Validator that we bind with guice, and our tests are failing with the error: [Guice/BindingAlreadySet]: Validator was bound multiple times. It listed both our validator and ru.vyarus.guice.validator.ValidationModule.

This only occurs in ci, which downloads freshly from maven. When we looked in our local maven cache, we see that the pom in dropwizard-guicey has changed dramatically. When we replace dropwizard-guicey with our local cached version, it passes fine.

xvik commented 4 months ago

Please share more details:

Sorry, without additional info it's hard to help you as I don't understand your problem (and can't reproduce it). Any other additional info could also be helpful (as much as you can). There were no big changes recently, except new release structure (5.8, 6.0, 7.0), maybe you jumped over it and this affected you (anyway need to know exact versions and some problem details to propose anything).

jdettmannnava commented 4 months ago

Sorry, I agree that the situation is difficult to describe. We noticed a big change in the dependencies associated with dropwizard-guicey 6.2.1 in the maven repository since last week, and we were hoping you could revert these changes. Or maybe you could give us advice on other ways to address the issue. We have inherited this code and are not DropWizard experts.

We have been using dropwizard-guicey 6.2.1 successfully, and we have made no changes to our code.

The code works fine in the application; it is just the integration tests that fail. These tests pass when run against the maven cache from last week. However, they fail when running against a fresh maven cache. They succeed when run against a fresh cache with the artifacts for dropwizard-guicey 6.2.1 copied into the maven cache.

We see drastic difference in the maven caches from between last week and this week. We trace these differences to the differences in the pom associated with dropwizard-guicey 6.2.1 in the maven repository.

The pom in mvn last week had the following artifactIds:

dropwizard-guicey guicey-admin-rest guicey-eventbus guicey-jdbi3 guicey-lifecycle-annotations guicey-server-pages guicey-spa guicey-test-junit4 guicey-test-spock guicey-validation

The current pom has these artifactIds:

dropwizard-guicey guice guice-servlet dropwizard-core generics-resolver jsr305 junit-jupiter-api dropwizard-testing guice-bridge

Differences in mvn dependency:tree

Last week:

[INFO] +- ru.vyarus:dropwizard-guicey:jar:6.2.1:compile [INFO] | +- com.google.inject:guice:jar:5.1.0:compile [INFO] | | +- javax.inject:javax.inject:jar:1:compile [INFO] | | - aopalliance:aopalliance:jar:1.0:compile [INFO] | +- com.google.inject.extensions:guice-servlet:jar:6.0.0:compile [INFO] | +- ru.vyarus:generics-resolver:jar:3.0.3:compile [INFO] | - com.google.code.findbugs:jsr305:jar:3.0.1:compile (optional)

This week:

[INFO] +- ru.vyarus:dropwizard-guicey:jar:6.2.1:compile [INFO] | +- ru.vyarus.dropwizard-guicey:dropwizard-guicey:jar:6.2.1:compile [INFO] | | +- com.google.inject.extensions:guice-servlet:jar:6.0.0:compile [INFO] | | - ru.vyarus:generics-resolver:jar:3.0.3:compile [INFO] | +- ru.vyarus.dropwizard-guicey:guicey-admin-rest:jar:6.2.1:compile [INFO] | +- ru.vyarus.dropwizard-guicey:guicey-eventbus:jar:6.2.1:compile [INFO] | +- ru.vyarus.dropwizard-guicey:guicey-jdbi3:jar:6.2.1:compile [INFO] | | +- io.dropwizard:dropwizard-jdbi3:jar:3.0.7:compile [INFO] | | | +- org.jdbi:jdbi3-core:jar:3.45.0:compile [INFO] | | | | - io.leangen.geantyref:geantyref:jar:1.3.15:compile [INFO] | | | +- org.jdbi:jdbi3-sqlobject:jar:3.45.0:compile [INFO] | | | +- org.jdbi:jdbi3-guava:jar:3.45.0:compile [INFO] | | | - io.dropwizard.metrics:metrics-jdbi3:jar:4.2.25:compile [INFO] | | - ru.vyarus:guice-ext-annotations:jar:1.4.1:compile [INFO] | +- ru.vyarus.dropwizard-guicey:guicey-lifecycle-annotations:jar:6.2.1:compile [INFO] | +- ru.vyarus.dropwizard-guicey:guicey-server-pages:jar:6.2.1:compile [INFO] | | - io.dropwizard:dropwizard-views:jar:3.0.7:compile [INFO] | +- ru.vyarus.dropwizard-guicey:guicey-spa:jar:6.2.1:compile [INFO] | | - io.dropwizard:dropwizard-assets:jar:3.0.7:compile [INFO] | +- ru.vyarus.dropwizard-guicey:guicey-test-junit4:jar:6.2.1:compile [INFO] | | +- com.github.stefanbirkner:system-rules:jar:1.19.0:compile [INFO] | | - io.dropwizard.modules:dropwizard-testing-junit4:jar:3.0.4:compile [INFO] | +- ru.vyarus.dropwizard-guicey:guicey-test-spock:jar:6.2.1:compile [INFO] | | - org.spockframework:spock-core:jar:1.3-groovy-2.5:compile [INFO] | | +- org.codehaus.groovy:groovy:jar:2.5.4:compile [INFO] | | +- org.codehaus.groovy:groovy-json:jar:2.5.4:compile [INFO] | | +- org.codehaus.groovy:groovy-nio:jar:2.5.4:compile [INFO] | | +- org.codehaus.groovy:groovy-macro:jar:2.5.4:compile [INFO] | | +- org.codehaus.groovy:groovy-templates:jar:2.5.4:compile [INFO] | | +- org.codehaus.groovy:groovy-test:jar:2.5.4:compile [INFO] | | +- org.codehaus.groovy:groovy-sql:jar:2.5.4:compile [INFO] | | - org.codehaus.groovy:groovy-xml:jar:2.5.4:compile [INFO] | - ru.vyarus.dropwizard-guicey:guicey-validation:jar:6.2.1:compile [INFO] | - ru.vyarus:guice-validator:jar:2.0.1:compile

Here is the failure message from the tests:

Unable to create injector, see the following errors:

1) [Guice/BindingAlreadySet]: Validator was bound multiple times.

Bound at: 1 : FHIRValidationModule.provideValidator(FHIRValidationModule.java:57) _ installed by: Elements$ElementsAsModule -> FHIRModule -> FHIRValidationModule 2 : ValidationModule.configure(ValidationModule.java:166) _ installed by: Elements$ElementsAsModule -> ValidationModule

Learn more: https://github.com/google/guice/wiki/BINDING_ALREADY_SET

2) [Guice/BindingAlreadySet]: ValidatorFactory was bound multiple times.

Bound at: 1 : FHIRValidationModule.configure(FHIRValidationModule.java:43) _ installed by: Elements$ElementsAsModule -> FHIRModule -> FHIRValidationModule 2 : ValidationModule.configure(ValidationModule.java:169) _ installed by: Elements$ElementsAsModule -> ValidationModule

Learn more: https://github.com/google/guice/wiki/BINDING_ALREADY_SET

2 errors

:Full classname legend: Elements$ElementsAsModule: "com.google.inject.spi.Elements$ElementsAsModule" FHIRModule: "gov.cms.dpc.fhir.FHIRModule" FHIRValidationModule: "gov.cms.dpc.fhir.validations.dropwizard.FHIRValidationModule" ValidationModule: "ru.vyarus.guice.validator.ValidationModule" Validator: "javax.validation.Validator" ValidatorFactory: "javax.validation.ValidatorFactory" :End of classname legend:

Here is the code where we bind:

import com.google.inject.AbstractModule;
...
public class FHIRValidationModule extends AbstractModule {
...
    @Override
    protected void configure() {

        // Create a multi-binder for automatically bundling and injecting a Set of ConstraintValidators
        TypeLiteral<ConstraintValidator<?, ?>> constraintType = new TypeLiteral<>() {
        };
        Multibinder<ConstraintValidator<?, ?>> constraintBinder = Multibinder.newSetBinder(binder(), constraintType);
        constraintBinder.addBinding().to(ProfileValidator.class);

        bind(ConstraintValidatorFactory.class).to(InjectingConstraintValidatorFactory.class);
        bind(ValidatorFactory.class).toProvider(ValidatorFactoryProvider.class);
        bind(ConfiguredValidator.class).to(InjectingConfiguredValidator.class);

        bind(DPCProfileSupport.class).in(Scopes.SINGLETON);
        bind(FhirValidator.class).toProvider(FHIRValidatorProvider.class);
    }
...
}
jdettmannnava commented 4 months ago

It looks like the artifact we are using moved down a level, so changing from

        <dependency>
            <groupId>ru.vyarus</groupId>
            <artifactId>dropwizard-guicey</artifactId>
        </dependency>

to

        <dependency>
            <groupId>ru.vyarus.dropwizard-guicey</groupId>
            <artifactId>dropwizard-guicey</artifactId>
        </dependency> 

fixed it.

xvik commented 4 months ago

You are using guicey artifacts from jitpack: "bad" one and "good" one

Please don't do it. It is not the same as the release version I publish into maven central.

Jitpack builds its own deliveries: this is great for snapshots, but not for releases (at least, for published into maven central).

Since I merged all guicey repositories into one (5.8 and above), jitpack can't properly build it. Unfortunately, I can't do anything with it (I tried, but can't make it work properly).

So please, use maven central version.

jdettmannnava commented 4 months ago

Thank you so much! We will start doing so ASAP.