Search code examples
mavenslf4jjboss-arquillianmaven-dependency

Arquillian testing: cannot remove dependencies to slf4j from the embedded glassfish


I'm creating a java EE integration test suite with arquillian and junit in a multi pom maven project. In the main pom I am including both the embedded glassfish required by arquillian and the slf4j library required by my project. The embedded glassfish contains a reference to slf4j itself, so I am trying to remove it by specifying an exclusion inside the dependency, as specified in http://www.slf4j.org/codes.html#multiple_bindings.

<dependency>
    <groupId>org.jboss.arquillian.container</groupId>
    <artifactId>arquillian-glassfish-embedded-3.1</artifactId>
    <version>1.0.0.CR4</version>
    <scope>test</scope>
    <exclusions>
        <exclusion>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-simple</artifactId>
        </exclusion>
        <exclusion>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-api</artifactId>
        </exclusion>
        <exclusion>
            <groupId>org.slf4j</groupId>
            <artifactId>jcl-over-slf4j</artifactId>
        </exclusion>
    </exclusions>
</dependency>

<dependency>
    <groupId>org.glassfish.main.extras</groupId>
    <artifactId>glassfish-embedded-all</artifactId>
    <version>3.1.2</version>
    <scope>test</scope>
    <exclusions>
        <exclusion>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-simple</artifactId>
        </exclusion>
        <exclusion>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-api</artifactId>
        </exclusion>
        <exclusion>
            <groupId>org.slf4j</groupId>
            <artifactId>jcl-over-slf4j</artifactId>
        </exclusion>
    </exclusions>
</dependency>


<dependency>
    <groupId>org.slf4j</groupId>
    <artifactId>slf4j-simple</artifactId>
    <version>1.7.19</version>
    <scope>test</scope>
</dependency>

However, whenever I start the tests, the slf4j dependency pops magically out

SLF4J: Class path contains multiple SLF4J bindings.

SLF4J: Found binding in [jar:file:/C:/Users/panda/.m2/repository/org/glassfish/main/extras/glassfish-embedded-all/3.1.2/glassfish-embedded-all-3.1.2.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/C:/Users/panda/.m2/repository/org/slf4j/slf4j-simple/1.5.10/slf4j-simple-1.5.10.jar!/org/slf4j/impl/StaticLoggerBinder.class]

SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.

Probably I'm missing something... What should be the right approach to remove the dependency to slf4j contained in the glassfish embedded jar?


Solution

  • No, you cannot.

    Since the glassfish-embedded-all-3.1.2.jar is an uber jar which contains the org/slf4j/* inside.

    You can extract your C:/Users/panda/.m2/repository/org/glassfish/main/extras/glassfish-embedded-all/3.1.2/glassfish-embedded-all-3.1.2.jar to see it further. Not only the slf4j but also every required packages are inside as well.

    If you look at its pom, there is no any dependency to the slf4j as well. It is a reason why you cannot exclude it via the dependency exclusion.