Maven: remove one transitive dependency

My project includes a jar file because it is listed as a transitive dependency.

However, I checked not only that I did not need it, but also caused problems, because the class inside the jar files changes the class that I need in another jar file.

How can I leave one jar file from my transitive dependencies?

+25
java maven-2 dependencies
May 03 '09 at 11:47
source share
3 answers

You can eliminate the dependency as follows:

<dependency> <groupId>org.springframework</groupId> <artifactId>spring</artifactId> <version>2.5.6</version> <exclusions> <exclusion> <groupId>commons-logging</groupId> <artifactId>commons-logging</artifactId> </exclusion> </exclusions> </dependency> 
+30
May 03 '09 at 12:11
source share
— -

The correct way is to use the exception mechanism, but sometimes you can use the following hack instead to avoid adding a lot of exceptions when many artifacts have the same transitive dependency that you want to ignore. Instead of specifying an exception, you define an additional dependency with the amount of "provided". This tells Maven that you will manually take care of providing this artifact at runtime, and therefore it will not be packaged. For example:

  <dependency> <groupId>org.springframework</groupId> <artifactId>spring</artifactId> <version>2.5.6</version> </dependency> <dependency> <groupId>commons-logging</groupId> <artifactId>commons-logging</artifactId> <version>1.1.1</version> <scope>provided</scope> </dependency> 

Side effect: you must specify the version of the ignored artifact, and its POM will be restored during assembly; this does not apply to regular exceptions. This can be a problem for you if you run your private Maven repository behind a firewall.

+15
May 03 '09 at 17:19
source share

You can do this by explicitly eliminating the problem artifact. Take a dependency that includes the problem and mark it to rule it out:

On the maven website:

 <dependency> <groupId>group-a</groupId> <artifactId>artifact-a</artifactId> <version>1.0</version> <exclusions> <exclusion> <groupId>group-c</groupId> <artifactId>excluded-artifact</artifactId> </exclusion> </exclusions> </dependency> 
+3
May 03 '09 at 12:09 a.m.
source share



All Articles