1

My project has some dependencies (really many) and I'm adding them in dependency. But I don't want any transitive dependency, that will be out of my control (maven brings me almost three times of what I need). I tried to ban transitive dependency in this way:

<exclusions>
        <exclusion>
            <groupId>*</groupId>
            <artifactId>*</artifactId>
        </exclusion>
</exclusions>

But after I did a mvn package, the transitive dependencies are still downloaded and added to my built package. Here is the logging of maven:

[DEBUG] Dependencies for project:com.XXX.XXX:
org.apache.XXX
org.apache.XXX.YYY
...
[DEBUG] Resolving project dependencies transitively:
[DEBUG] org.com.XXX.yyy
[DEBUG]    org.apache.ZZZ
...
[DEBUG] Adding artifact: org.apache.ZZZ with file: ${file name} to assembly location: lib/${file name}.jar
...

So this is not what I want. I want either maven DON'T automatically download transitive dependencies or don't add them into my 'mvn package'.

Appreciate any help.

pythonician_plus_plus
  • 1,244
  • 3
  • 15
  • 38
  • Duplicate of http://stackoverflow.com/questions/547805/exclude-all-transitive-dependencies-of-a-single-dependency – BadZen May 19 '15 at 18:38
  • That answer just doesn't work. Please read through the question description before mark it as 'duplicate' – pythonician_plus_plus May 19 '15 at 18:44
  • "For maven 2 I'd recommend creating your own custom pom for the dependency that has your . For projects that need to use that dependency, set the dependency to your custom pom instead of the typical artifact." – BadZen May 19 '15 at 18:45
  • You're saying you did that? Or you put the excludes right in you project POM? The functionality you are asking for is exactly that in the question above, and it definitely works. – BadZen May 19 '15 at 18:46
  • I'm using maven 3 and I want all the transitive dependencies be excluded. Having own in custom pom works for a number of dependency if I can figure out how many and what are the exclusions. But if I have more than a few, say 100 dependency, than build my own exclusions is not practical. – pythonician_plus_plus May 19 '15 at 18:51
  • maybe * doesn't work in exclusions... – rogerdpack May 19 '15 at 19:12

1 Answers1

0

So here is the solution I've got. Maven is still grabbing the transitive dependency needed. What I did is to include only the jars I want in assembly stage. Within assembly configuration file, I manually add the jars I want in

<dependencyset>
   <includes>
      <include>com.XXX:XXX:jar:2.6.0</include>
   </includes>
<dependencyset>

Compare to what I don't want (several hundred of transitive dependency jars), it's more practical to add what I want. This solves the issue nicely.

pythonician_plus_plus
  • 1,244
  • 3
  • 15
  • 38