How to exclude test dependencies from a shaded maven jar?

蹲街弑〆低调 提交于 2021-01-22 06:33:24

问题


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:


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


来源:https://stackoverflow.com/questions/16466490/how-to-exclude-test-dependencies-from-a-shaded-maven-jar

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!