Run unit tests with dependencies that are in the exclusions group

1

I have a scenario where I need to run a test with JUnit on a feature that has an external dependency, but to run this functionality on the application server I need to put this external dependency in the exclusions group on my pom.xml . But in the test I do not need / have the JBoss EAP 5 container started, which already has this dependency. And at this point the test blames that dependency is not available.

Below I put the dependency in question:

<dependency>
    <groupId>net.sourceforge.nekohtml</groupId>
    <artifactId>nekohtml</artifactId>
    <version>1.9.21</version>
    <exclusions>
        <exclusion>
            <groupId>xerces</groupId>
            <artifactId>xercesImpl</artifactId>
        </exclusion>
        <exclusion>
            <groupId>xml-apis</groupId>
            <artifactId>xml-apis</artifactId>
        </exclusion>
    </exclusions>
</dependency>
    
asked by anonymous 30.10.2014 / 12:33

1 answer

2

Try explicitly adding the two transitive dependencies that you deleted by adding nekohtml , setting test scope to them:

<dependency>
    <groupId>xerces</groupId>
    <artifactId>xercesImpl</artifactId>
    <scope>test</scope>
</dependency>
<dependency>
    <groupId>xml-apis</groupId>
    <artifactId>xml-apis</artifactId>
    <scope>test</scope>
</dependency>

Note the tag I added, <scope>test</scope> . This will make this dependency available during testing and will keep the dependency out of the distribution package.

If these dependencies are required also for the production code and not just for the test code, you can use the provided scope ( <scope>provided</scope> ), so the dependencies will be used during compilation and during testing, but will not be included in the distribution package.

    
30.10.2014 / 12:52