I'm using maven to build an executable JAR and I want to add all dependencies minus a select few to the Class-Path of my MANIFEST.MF. So far I'm using the maven-jar-plugin for this:
<!-- Add dependent JARs to the classpath -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<classpathPrefix>libraries</classpathPrefix>
<mainClass>MyMainClass</mainClass>
</manifest>
<manifestEntries>
<Built-By>Me</Built-By>
</manifestEntries>
</archive>
</configuration>
</plugin>
This works for adding all dependencies. However, I furthermore want to exclude certain dependencies from being added to the Class-Path. According to the documentation you can use the exclude tag as follows:
<configuration>
<!-- ... -->
<excludes>
<exclude>**selenium*</exclude>
</excludes>
<!-- ... -->
</configuration>
I would expect this to exclude any dependency which has selenium in the name but it does not work. For example I would like to exclude libraries/selenium-json-4.0.0-alpha-6.jar from the Class-Path. Even if I specify that exact name it does not exclude anything. I would also like to provide the groupId for exclusion similar to how the maven-dependency-plugin's excludeGroupIds tag works.
How can the desired Class-Path management be done using maven?
I'm also using maven-shade-plugin for building the executable (fat) JAR but its manifest manipulation facilities seem lesser known/documented. Setting the Class-Path using maven-shade-plugin via this answer works but how can I populate my dependencies with exclusions instead of hard-coding everything?