Sunday, November 18, 2007

Maven and Excluding Transitive Dependencies

Warning, this is just another maven rant...

Why has someone concluded, that we do not need to exclude all transitive dependencies of some dependency?

More than once have I had the need to grab a dependency, but then exclude all or a lot by wildcard, of the incoming transitive dependencies. I cannot even exclude all artifacts from a group of transitive dependencies, without explicitly mentioning each and every of the transitive dependencies that I wont need.

If I do:
<dependency>
<groupId>org.acegisecurity</groupId>
<artifactId>acegi-security</artifactId>
<version>1.0.4</version>
</dependency>
And I do not want all the spring stuff, it comes with, I cannot write:
<dependency>
<groupId>org.acegisecurity</groupId>
<artifactId>acegi-security</artifactId>
<version>1.0.4</version>
<exclusions>
<exclusion>
<groupId>org.springframework</groupId>
<artifactId>*</artifactId>
</exclusion>
</exclusions>
</dependency>
or something like it. No no, I will have to do:
<dependency>
<groupId>org.acegisecurity</groupId>
<artifactId>acegi-security</artifactId>
<version>1.0.4</version>
<exclusions>
<exclusion>
<groupId>org.springframework</groupId>
<artifactId>spring-mock</artifactId>
</exclusion>
<exclusion>
<groupId>org.springframework</groupId>
<artifactId>spring-remoting</artifactId>
</exclusion>
<exclusion>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
</exclusion>
<exclusion>
<groupId>org.springframework</groupId>
<artifactId>spring-support</artifactId>
</exclusion>
</exclusions>
</dependency>
Or am I missing how to do this? Please correct me if I am wrong!

5 comments:

Zarar Siddiqi said...

You're right, that's how you would do it. But if it's so much of a pain for you just download it and install it in a local repo with no dependencies.

Per Olesen said...

Yes, I could just download and install it locally. But that would put a pain on others, who need to do the same, to be able to build it. Not nice.

Per Olesen said...

BTW, there is an issue in the Jira instance on maven on this. It is a bit old, but if you think like me, please go vote for it here: http://jira.codehaus.org/browse/MNG-2315

Per Olesen said...

Here's the link as a link: http://jira.codehaus.org/browse/MNG-2315

Anonymous said...

I agree. This is a royal pain in the ass. This is increasingly becoming a larger problem with open source projects now because they don't see it as a big problem since they use the public repositories. For those of us that use internal repositories this can be a major pain. I find myself downloading jars built with maven and yanking out the embedded pom. This forces my internal repository to create a generic pom which does not have any dependencies.