I have a project which is having multiple modules within it. One of the module, say "main", is having my service class, "MyService.class". Dropwizard has a jar - dropwizard-core. I want this jar in more than one module, so I was thinking of keeping its dependency in parent POM. By doing that, while running my dropwizard service file, I am encountering an exception as follows:
SLF4J: Class path contains multiple SLF4J bindings.<br>
SLF4J: Found binding in [jar:file:/home/username/.m2/repository/org/slf4j/slf4j-simple/1.7.12/slf4j-simple-1.7.12.jar!/org/slf4j/impl/StaticLoggerBinder.class]<br>
SLF4J: Found binding in [jar:file:/home/username/.m2/repository/ch/qos/logback/logback-classic/1.1.3/logback-classic-1.1.3.jar!/org/slf4j/impl/StaticLoggerBinder.class]<br>
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.<br>
SLF4J: Actual binding is of type [org.slf4j.impl.SimpleLoggerFactory]<br><br>
Exception in thread "main" java.lang.IllegalStateException: Unable to acquire the logger context
at io.dropwizard.logging.LoggingUtil.getLoggerContext(LoggingUtil.java:46)
at io.dropwizard.logging.BootstrapLogging.bootstrap(BootstrapLogging.java:45)
at io.dropwizard.logging.BootstrapLogging.bootstrap(BootstrapLogging.java:34)
at io.dropwizard.Application.<init>(Application.java:24)
at my.project.package.MyService.<init>(MyService.java:31)
at my.project.package.MyService.main(MyService.java:38)
This project runs perfectly fine if I put the dependency in the POM of "main" module.
Dropwizard is binding with wrong logger and that is the reason behind this exception. But this binding happens in the background and I have no control over it.
I am also sharing the dependency tree for both the scenarios.
Case 1 : When dropwizard-core is in child POM (main module) :
my.groupId.myProject:myProject-main:jar:1.0-SNAPSHOT<br>
[INFO] +- io.dropwizard:dropwizard-core:jar:0.9.2:compile<br>
[INFO] | +- io.dropwizard:dropwizard-util:jar:0.9.2:compile<br>
[INFO] | | +- com.fasterxml.jackson.core:jackson-annotations:jar:2.6.0:compile<br>
[INFO] | | +- com.google.guava:guava:jar:18.0:compile<br>
[INFO] | | +- com.google.code.findbugs:jsr305:jar:3.0.1:compile<br>
[INFO] | | \- joda-time:joda-time:jar:2.9:compile<br>
[INFO] | +- io.dropwizard:dropwizard-jackson:jar:0.9.2:compile<br>
[INFO] | | +- com.fasterxml.jackson.core:jackson-core:jar:2.6.3:compile<br>
[INFO] | | +- com.fasterxml.jackson.core:jackson-databind:jar:2.6.3:compile<br>
[INFO] | | +- com.fasterxml.jackson.datatype:jackson-datatype-jdk7:jar:2.6.3:compile<br>
[INFO] | | +- com.fasterxml.jackson.datatype:jackson-datatype-guava:jar:2.6.3:compile<br>
[INFO] | | +- com.fasterxml.jackson.module:jackson-module-afterburner:jar:2.6.3:compile<br>
[INFO] | | +- com.fasterxml.jackson.datatype:jackson-datatype-joda:jar:2.6.3:compile<br>
[INFO] | | +- org.slf4j:slf4j-api:jar:1.7.12:compile<br>
[INFO] | | \- ch.qos.logback:logback-classic:jar:1.1.3:compile<br>
[INFO] | +- io.dropwizard:dropwizard-validation:jar:0.9.2:compile<br>
[INFO] | | +- org.hibernate:hibernate-validator:jar:5.2.2.Final:compile<br>
[INFO] | | | +- javax.validation:validation-api:jar:1.1.0.Final:compile<br>
[INFO] | | | +- org.jboss.logging:jboss-logging:jar:3.2.1.Final:compile<br>
[INFO] | | | \- com.fasterxml:classmate:jar:1.1.0:compile<br>
[INFO] | | \- org.glassfish:javax.el:jar:3.0.0:compile<br>
[INFO] | +- io.dropwizard:dropwizard-configuration:jar:0.9.2:compile<br>
[INFO] | | +- com.fasterxml.jackson.dataformat:jackson-dataformat-yaml:jar:2.6.3:compile<br>
[INFO] | | | \- org.yaml:snakeyaml:jar:1.15:compile<br>
[INFO] | | \- org.apache.commons:commons-lang3:jar:3.4:compile<br>
[INFO] | +- io.dropwizard:dropwizard-logging:jar:0.9.2:compile<br>
[INFO] | | +- io.dropwizard.metrics:metrics-logback:jar:3.1.2:compile<br>
[INFO] | | +- org.slf4j:jul-to-slf4j:jar:1.7.12:compile<br><br>
[INFO] | | +- ch.qos.logback:logback-core:jar:1.1.3:compile<br>
[INFO] | | +- org.slf4j:log4j-over-slf4j:jar:1.7.12:compile<br>
[INFO] | | +- org.slf4j:jcl-over-slf4j:jar:1.7.12:compile<br>
[INFO] | | \- org.eclipse.jetty:jetty-util:jar:9.2.13.v20150730:compile<br>
[INFO] | +- io.dropwizard:dropwizard-metrics:jar:0.9.2:compile<br>
[INFO] | +- io.dropwizard:dropwizard-jersey:jar:0.9.2:compile<br>
[INFO] | | +- org.glassfish.jersey.core:jersey-server:jar:2.22.1:compile<br>
[INFO] | | | +- org.glassfish.jersey.core:jersey-common:jar:2.22.1:compile<br>
[INFO] | | | | +- org.glassfish.jersey.bundles.repackaged:jersey-guava:jar:2.22.1:compile<br>
[INFO] | | | | \- org.glassfish.hk2:osgi-resource-locator:jar:1.0.1:compile<br>
[INFO] | | | +- javax.ws.rs:javax.ws.rs-api:jar:2.0.1:compile<br>
[INFO] | | | +- org.glassfish.jersey.media:jersey-media-jaxb:jar:2.22.1:compile<br>
[INFO] | | | +- javax.annotation:javax.annotation-api:jar:1.2:compile<br>
[INFO] | | | +- org.glassfish.hk2:hk2-api:jar:2.4.0-b31:compile<br>
[INFO] | | | | +- org.glassfish.hk2:hk2-utils:jar:2.4.0-b31:compile<br>
[INFO] | | | | \- org.glassfish.hk2.external:aopalliance-repackaged:jar:2.4.0-b31:compile<br>
[INFO] | | | +- org.glassfish.hk2.external:javax.inject:jar:2.4.0-b31:compile<br>
[INFO] | | | \- org.glassfish.hk2:hk2-locator:jar:2.4.0-b31:compile<br>
[INFO] | | | \- org.javassist:javassist:jar:3.18.1-GA:compile<br>
[INFO] | | +- org.glassfish.jersey.ext:jersey-metainf-services:jar:2.22.1:compile<br>
[INFO] | | +- org.glassfish.jersey.ext:jersey-bean-validation:jar:2.22.1:compile<br>
[INFO] | | +- io.dropwizard.metrics:metrics-jersey2:jar:3.1.2:compile<br>
[INFO] | | +- com.fasterxml.jackson.jaxrs:jackson-jaxrs-json-provider:jar:2.6.3:compile<br>
[INFO] | | | +- com.fasterxml.jackson.jaxrs:jackson-jaxrs-base:jar:2.6.3:compile<br>
[INFO] | | | \- com.fasterxml.jackson.module:jackson-module-jaxb-annotations:jar:2.6.3:compile<br>
[INFO] | | +- org.glassfish.jersey.containers:jersey-container-servlet:jar:2.22.1:compile<br>
[INFO] | | | \- org.glassfish.jersey.containers:jersey-container-servlet-core:jar:2.22.1:compile<br>
[INFO] | | +- org.eclipse.jetty:jetty-server:jar:9.2.13.v20150730:compile<br>
[INFO] | | | +- javax.servlet:javax.servlet-api:jar:3.1.0:compile<br>
[INFO] | | | \- org.eclipse.jetty:jetty-io:jar:9.2.13.v20150730:compile<br>
[INFO] | | +- org.eclipse.jetty:jetty-webapp:jar:9.2.13.v20150730:compile<br>
[INFO] | | | \- org.eclipse.jetty:jetty-xml:jar:9.2.13.v20150730:compile<br>
[INFO] | | \- org.eclipse.jetty:jetty-continuation:jar:9.2.13.v20150730:compile<br>
[INFO] | +- io.dropwizard:dropwizard-servlets:jar:0.9.2:compile<br>
[INFO] | | \- io.dropwizard.metrics:metrics-annotation:jar:3.1.2:compile<br>
[INFO] | +- io.dropwizard:dropwizard-jetty:jar:0.9.2:compile<br>
[INFO] | | +- io.dropwizard.metrics:metrics-jetty9:jar:3.1.2:compile<br>
[INFO] | | +- org.eclipse.jetty:jetty-servlet:jar:9.2.13.v20150730:compile<br>
[INFO] | | | \- org.eclipse.jetty:jetty-security:jar:9.2.13.v20150730:compile<br>
[INFO] | | +- org.eclipse.jetty:jetty-servlets:jar:9.2.13.v20150730:compile<br>
[INFO] | | \- org.eclipse.jetty:jetty-http:jar:9.2.13.v20150730:compile<br>
[INFO] | +- io.dropwizard:dropwizard-lifecycle:jar:0.9.2:compile<br>
[INFO] | +- io.dropwizard.metrics:metrics-core:jar:3.1.2:compile<br>
[INFO] | +- io.dropwizard.metrics:metrics-jvm:jar:3.1.2:compile<br>
[INFO] | +- io.dropwizard.metrics:metrics-servlets:jar:3.1.2:compile<br>
[INFO] | | \- io.dropwizard.metrics:metrics-json:jar:3.1.2:compile<br>
[INFO] | +- io.dropwizard.metrics:metrics-healthchecks:jar:3.1.2:compile<br>
[INFO] | +- net.sourceforge.argparse4j:argparse4j:jar:0.6.0:compile<br>
[INFO] | \- org.eclipse.jetty.toolchain.setuid:jetty-setuid-java:jar:1.0.3:compile<br>
[INFO] +- de.thomaskrille:dropwizard-template-config:jar:1.1.0:compile<br>
[INFO] +- my.groupId.myProject:myProject-module1:jar:1.0-SNAPSHOT:compile<br>
[INFO] +- my.groupId.myProject:myProject-module2:jar:1.0-SNAPSHOT:compile<br>
[INFO] +- my.groupId.myProject:myProject-module3:jar:0.0.1-SNAPSHOT:compile<br>
[INFO] | +- io.dropwizard:dropwizard-auth:jar:0.9.1:compile<br>
[INFO] | \- io.dropwizard:dropwizard-client:jar:0.9.1:compile<br>
[INFO] | +- org.glassfish.jersey.core:jersey-client:jar:2.22.1:compile<br>
[INFO] | +- org.apache.httpcomponents:httpclient:jar:4.5.1:compile<br>
[INFO] | | +- org.apache.httpcomponents:httpcore:jar:4.4.3:compile<br>
[INFO] | | \- commons-codec:commons-codec:jar:1.9:compile<br>
[INFO] | +- io.dropwizard.metrics:metrics-httpclient:jar:3.1.2:compile<br>
[INFO] | \- org.glassfish.jersey.connectors:jersey-apache-connector:jar:2.22.1:compile<br>
[INFO] +- junit:junit:jar:4.12:test<br>
[INFO] | \- org.hamcrest:hamcrest-core:jar:1.3:test<br>
[INFO] +- org.hamcrest:hamcrest-library:jar:1.3:test<br>
[INFO] \- org.mockito:mockito-core:jar:1.10.19:test<br>
[INFO] \- org.objenesis:objenesis:jar:2.1:test<br>
**Case 2 : When dropwizard-core is in parent POM :**
my.groupId.myProject:myProject-main:jar:jar:1.0-SNAPSHOT<br>
[INFO] +- de.thomaskrille:dropwizard-template-config:jar:1.1.0:compile<br>
[INFO] +- my.groupId.myProject:myProject-module1:jar:1.0-SNAPSHOT:compile<br>
[INFO] +- my.groupId.myProject:myProject-module2:jar:1.0-SNAPSHOT:compile<br>
[INFO] +- my.groupId.myProject:myProject-common:jar:0.0.1-SNAPSHOT:compile<br>
[INFO] | +- io.dropwizard:dropwizard-auth:jar:0.9.1:compile<br>
[INFO] | \- io.dropwizard:dropwizard-client:jar:0.9.1:compile<br>
[INFO] | +- org.glassfish.jersey.core:jersey-client:jar:2.22.1:compile<br>
[INFO] | | +- javax.ws.rs:javax.ws.rs-api:jar:2.0.1:compile<br>
[INFO] | | +- org.glassfish.jersey.core:jersey-common:jar:2.22.1:compile<br>
[INFO] | | | +- org.glassfish.jersey.bundles.repackaged:jersey-guava:jar:2.22.1:compile<br>
[INFO] | | | \- org.glassfish.hk2:osgi-resource-locator:jar:1.0.1:compile<br>
[INFO] | | +- org.glassfish.hk2:hk2-api:jar:2.4.0-b31:compile<br>
[INFO] | | | +- org.glassfish.hk2:hk2-utils:jar:2.4.0-b31:compile<br>
[INFO] | | | \- org.glassfish.hk2.external:aopalliance-repackaged:jar:2.4.0-b31:compile<br>
[INFO] | | +- org.glassfish.hk2.external:javax.inject:jar:2.4.0-b31:compile<br>
[INFO] | | \- org.glassfish.hk2:hk2-locator:jar:2.4.0-b31:compile<br>
[INFO] | | \- org.javassist:javassist:jar:3.18.1-GA:compile<br>
[INFO] | +- org.apache.httpcomponents:httpclient:jar:4.5.1:compile<br>
[INFO] | | +- org.apache.httpcomponents:httpcore:jar:4.4.3:compile<br>
[INFO] | | \- commons-codec:commons-codec:jar:1.9:compile<br>
[INFO] | +- io.dropwizard.metrics:metrics-httpclient:jar:3.1.2:compile<br>
[INFO] | \- org.glassfish.jersey.connectors:jersey-apache-connector:jar:2.22.1:compile<br>
[INFO] +- io.dropwizard:dropwizard-core:jar:0.9.2:compile<br>
[INFO] | +- io.dropwizard:dropwizard-util:jar:0.9.2:compile<br>
[INFO] | | +- com.fasterxml.jackson.core:jackson-annotations:jar:2.6.0:compile<br>
[INFO] | | +- com.google.guava:guava:jar:18.0:compile<br>
[INFO] | | +- com.google.code.findbugs:jsr305:jar:3.0.1:compile<br>
[INFO] | | \- joda-time:joda-time:jar:2.9:compile<br>
[INFO] | +- io.dropwizard:dropwizard-jackson:jar:0.9.2:compile<br>
[INFO] | | +- com.fasterxml.jackson.core:jackson-core:jar:2.6.3:compile<br>
[INFO] | | +- com.fasterxml.jackson.core:jackson-databind:jar:2.6.3:compile<br>
[INFO] | | +- com.fasterxml.jackson.datatype:jackson-datatype-jdk7:jar:2.6.3:compile<br>
[INFO] | | +- com.fasterxml.jackson.datatype:jackson-datatype-guava:jar:2.6.3:compile<br>
[INFO] | | +- com.fasterxml.jackson.module:jackson-module-afterburner:jar:2.6.3:compile<br>
[INFO] | | +- com.fasterxml.jackson.datatype:jackson-datatype-joda:jar:2.6.3:compile<br>
[INFO] | | +- org.slf4j:slf4j-api:jar:1.7.12:compile<br>
[INFO] | | \- ch.qos.logback:logback-classic:jar:1.1.3:compile<br>
[INFO] | +- io.dropwizard:dropwizard-validation:jar:0.9.2:compile<br>
[INFO] | | +- org.hibernate:hibernate-validator:jar:5.2.2.Final:compile<br>
[INFO] | | | +- javax.validation:validation-api:jar:1.1.0.Final:compile<br>
[INFO] | | | +- org.jboss.logging:jboss-logging:jar:3.2.1.Final:compile<br>
[INFO] | | | \- com.fasterxml:classmate:jar:1.1.0:compile<br>
[INFO] | | \- org.glassfish:javax.el:jar:3.0.0:compile<br>
[INFO] | +- io.dropwizard:dropwizard-configuration:jar:0.9.2:compile<br>
[INFO] | | +- com.fasterxml.jackson.dataformat:jackson-dataformat-yaml:jar:2.6.3:compile<br>
[INFO] | | | \- org.yaml:snakeyaml:jar:1.15:compile<br>
[INFO] | | \- org.apache.commons:commons-lang3:jar:3.4:compile<br>
[INFO] | +- io.dropwizard:dropwizard-logging:jar:0.9.2:compile<br>
[INFO] | | +- io.dropwizard.metrics:metrics-logback:jar:3.1.2:compile<br>
[INFO] | | +- org.slf4j:jul-to-slf4j:jar:1.7.12:compile<br>
[INFO] | | +- ch.qos.logback:logback-core:jar:1.1.3:compile<br>
[INFO] | | +- org.slf4j:log4j-over-slf4j:jar:1.7.12:compile<br>
[INFO] | | +- org.slf4j:jcl-over-slf4j:jar:1.7.12:compile<br>
[INFO] | | \- org.eclipse.jetty:jetty-util:jar:9.2.13.v20150730:compile<br>
[INFO] | +- io.dropwizard:dropwizard-metrics:jar:0.9.2:compile<br>
[INFO] | +- io.dropwizard:dropwizard-jersey:jar:0.9.2:compile<br>
[INFO] | | +- org.glassfish.jersey.core:jersey-server:jar:2.22.1:compile<br>
[INFO] | | | +- org.glassfish.jersey.media:jersey-media-jaxb:jar:2.22.1:compile<br>
[INFO] | | | \- javax.annotation:javax.annotation-api:jar:1.2:compile<br>
[INFO] | | +- org.glassfish.jersey.ext:jersey-metainf-services:jar:2.22.1:compile<br>
[INFO] | | +- org.glassfish.jersey.ext:jersey-bean-validation:jar:2.22.1:compile<br>
[INFO] | | +- io.dropwizard.metrics:metrics-jersey2:jar:3.1.2:compile<br>
[INFO] | | +- com.fasterxml.jackson.jaxrs:jackson-jaxrs-json-provider:jar:2.6.3:compile<br>
[INFO] | | | +- com.fasterxml.jackson.jaxrs:jackson-jaxrs-base:jar:2.6.3:compile<br>
[INFO] | | | \- com.fasterxml.jackson.module:jackson-module-jaxb-annotations:jar:2.6.3:compile<br>
[INFO] | | +- org.glassfish.jersey.containers:jersey-container-servlet:jar:2.22.1:compile<br>
[INFO] | | | \- org.glassfish.jersey.containers:jersey-container-servlet-core:jar:2.22.1:compile<br>
[INFO] | | +- org.eclipse.jetty:jetty-server:jar:9.2.13.v20150730:compile<br>
[INFO] | | | +- javax.servlet:javax.servlet-api:jar:3.1.0:compile<br>
[INFO] | | | \- org.eclipse.jetty:jetty-io:jar:9.2.13.v20150730:compile<br>
[INFO] | | +- org.eclipse.jetty:jetty-webapp:jar:9.2.13.v20150730:compile<br>
[INFO] | | | \- org.eclipse.jetty:jetty-xml:jar:9.2.13.v20150730:compile<br>
[INFO] | | \- org.eclipse.jetty:jetty-continuation:jar:9.2.13.v20150730:compile<br>
[INFO] | +- io.dropwizard:dropwizard-servlets:jar:0.9.2:compile<br>
[INFO] | | \- io.dropwizard.metrics:metrics-annotation:jar:3.1.2:compile<br>
[INFO] | +- io.dropwizard:dropwizard-jetty:jar:0.9.2:compile<br>
[INFO] | | +- io.dropwizard.metrics:metrics-jetty9:jar:3.1.2:compile<br>
[INFO] | | +- org.eclipse.jetty:jetty-servlet:jar:9.2.13.v20150730:compile<br>
[INFO] | | | \- org.eclipse.jetty:jetty-security:jar:9.2.13.v20150730:compile<br>
[INFO] | | +- org.eclipse.jetty:jetty-servlets:jar:9.2.13.v20150730:compile<br>
[INFO] | | \- org.eclipse.jetty:jetty-http:jar:9.2.13.v20150730:compile<br>
[INFO] | +- io.dropwizard:dropwizard-lifecycle:jar:0.9.2:compile<br>
[INFO] | +- io.dropwizard.metrics:metrics-core:jar:3.1.2:compile<br>
[INFO] | +- io.dropwizard.metrics:metrics-jvm:jar:3.1.2:compile<br>
[INFO] | +- io.dropwizard.metrics:metrics-servlets:jar:3.1.2:compile<br>
[INFO] | | \- io.dropwizard.metrics:metrics-json:jar:3.1.2:compile<br>
[INFO] | +- io.dropwizard.metrics:metrics-healthchecks:jar:3.1.2:compile<br>
[INFO] | +- net.sourceforge.argparse4j:argparse4j:jar:0.6.0:compile<br>
[INFO] | \- org.eclipse.jetty.toolchain.setuid:jetty-setuid-java:jar:1.0.3:compile<br>
[INFO] +- junit:junit:jar:4.12:test<br>
[INFO] | \- org.hamcrest:hamcrest-core:jar:1.3:test<br>
[INFO] +- org.hamcrest:hamcrest-library:jar:1.3:test<br>
[INFO] \- org.mockito:mockito-core:jar:1.10.19:test<br>
[INFO] \- org.objenesis:objenesis:jar:2.1:test<br>
If anyone could come up with a possible reasoning, it would be of great help.
Thanks.