Excluding .class file from jar maven dependency
Use maven-jar-plugin
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<version>2.3.1</version>
<executions>
<execution>
<id>default-jar</id>
<phase>package</phase>
<goals>
<goal>jar</goal>
</goals>
<configuration>
<excludes>
<exclude><!-- package you want to exclude --></exclude>
</excludes>
</configuration>
</execution>
</executions>
</plugin>
source to share
There is no quick and easy way to do this. If you add the JAR as a dependency on your project, the JAR will be added to the test or compile the classpath (based on the scope you provided).
maven-dependency-plugin
provides a target unpack
that can be used to unpack artifacts into a specific directory.
As a work around for your problem, you can unpack the C artifact into A target / classes at build time. The target unpack
provides the ability to exclude certain file patterns (so you can exclude certain classes).
Also make sure the C JAR is not added to the class A path (adjust your dependencies accordingly), maybe add a dependency for the C type pom
instead jar
).
https://maven.apache.org/plugins/maven-dependency-plugin/unpack-mojo.html
How to exclude C-jar from A without changing B
<dependency>
<artifactId>B</artifactId>
<groupId>bgroupId</groupId>
<version>bverison</version>
<exclusions>
<exclusion>
<artifactId>C</artifactId>
<groupId>cgroupId</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<artifactId>C</artifactId>
<groupId>cgroupId</groupId>
<version>cverison</version>
<type>pom</type>
<exclusions>
<exclusion>
<artifactId>*</artifactId>
<groupId>*</groupId>
</exclusion>
</exclusions>
</dependency>
You can now use the dependency plugin to unpack the C JAR appropriately (excluding certain files)
source to share