Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Maven dependency: exclude one class

For example I have dependency:

<dependency>
    <groupId>org.slf4j</groupId>
    <artifactId>slf4j-api</artifactId>
    <version>1.5.6</version>
</dependency>  

Can I exclude one class, for example org/slf4j/Marker.class?

like image 245
Ilya Avatar asked Apr 10 '12 09:04

Ilya


People also ask

Can we exclude a class from Maven dependency?

Excluding a single class in not possible. Within <dependency> tags you can define <exclusions/> . However, these are for entire dependencies. The shade plugin should be handled with care.

How you can exclude dependency in Maven?

Exclude a dependency You can use a diagram to exclude a dependency from the project's POM. Select a dependency in the diagram window. From the context menu, choose Exclude. From the list, select the module (if any) where the exclusion definition will be added.

Can you exclude a class from a jar?

How to include/exclude content from jar artifact. Specify a list of fileset patterns to be included or excluded by adding <includes> / <include> or <excludes> / <exclude> in your pom. xml . Note that the patterns need to be relative to the path specified for the plugin's classesDirectory parameter.

How do you exclude a transitive dependency in Maven?

To avoid this, you can use Maven's <exclusions> tag. Consider below Maven dependency of spring-json library. Adding this dependency of spring-json library would include following jar files automatically. Note how we specified <exclusion> tag to remove spring and cglib dependencies from the transitive dependency tree.


1 Answers

Try it with the shade plugin

Details on why use shade and basic usage

like image 95
sfk Avatar answered Sep 22 '22 07:09

sfk