6

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?

AHungerArtist
  • 9,332
  • 17
  • 73
  • 109
  • 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 May 09 '13 at 20:13
  • @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 May 10 '13 at 13:28

1 Answers1

8

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
rzymek
  • 9,064
  • 2
  • 45
  • 59
  • @ryzmek 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 included the .java files in its jar, and I didn't notice the extension when I was looking at the shaded jar. – AHungerArtist May 10 '13 at 13:28
  • I thought it might be the case. That's why I suggested `dependency:tree`. It's a really useful tool – rzymek May 10 '13 at 14:04