Search code examples
mavenmaven-assembly-plugintransitive-dependency

How to exclude transitive dependencies with scope provided with maven-assembly-plugin?


I need to create a jar-with-dependencies. I'm using maven assemply plugin 3.1.0.

I want to:

  • include dependencies with scope compile and that, transitively
  • exclude dependencies with scope provided.

IE, in the following case as shown by mvn dependency:tree:

[INFO] +- com.jayway.jsonpath:json-path:jar:2.2.0:compile
[INFO] |  +- net.minidev:json-smart:jar:2.2.1:compile
[INFO] |  |  \- net.minidev:accessors-smart:jar:1.1:compile
[INFO] |  \- org.slf4j:slf4j-api:jar:1.7.16:provided

I want to include in the final jar json-path, json-smart, accessors-smart but NOT slf4j-api.

With the default jar-with-dependencies descriptor, I also have slf4j-api included in the resulting jar.

1/ Is it the intended behavior? This seem in contradiction with other maven resolution.

2/ what is assembly descriptor that allows to get what I want?

Thanks


Solution

  • So, it seems to just not work with the assembly plugin, and until explained why it is otherwise, I believe it's a bug: https://issues.apache.org/jira/browse/MASSEMBLY-883

    I created a minimal project to demonstrate the problem here: https://github.com/fanf/test-maven-assembly

    The solution is to use the shade plugin (https://maven.apache.org/plugins/maven-shade-plugin) which is correctly excluding transitive dependencies with scope provided (and can do many more things than the assembly plugin regarding uber-jar).