6
votes

I'm using the maven-shade-plugin and I'd like to exclude not only my test code, but my test dependencies in the shaded jar. I realize I can specifically exclude certain artifacts (like junit), but that's a good bit of work and prone to some error most likely.

I'm setting minimizeJar to true, but I still see my Junit and Mockito dependencies showing up. Is there just no way to exclude all test scoped dependencies via configuration?

1
Which version of shade plugin are you using? And how does your pom look like? I created a test project with Junit as test scope and the shade plugin did not package it. it is possible that one other lib not in test scope has Junit as dependency? - mszalbach
@mszalbach It was a combination of two things: One, there was a test dependency that was mistakenly declared as compile. Two, there was a test dependency that include the .java files in its jar, and I didn't notice the extension when I was looking at the shaded jar. So, you're right, the test dependency .class files do not get packaged. - AHungerArtist

1 Answers

8
votes

Make sure your test dependencies in the test scope:

<dependencies>
    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>4.11</version>
        <scope>test</scope>
    </dependency>
...

To check if your dependency setup use

mvn dependency:tree