Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I exclude *.DSA and *.SF files from shaded jar?

I have a section in pom.xml

 <filters>
   <filter>
      <artifact>*:*</artifact>
         <excludes>
            <exclude>META-INF/*.SF</exclude>
            <exclude>META-INF/*.DSA</exclude>
         </excludes>
   </filter>
</filters>

I want to exclude *.SF and *.DSA files from final jar. But I get the following message:

[INFO] No artifact matching filter *:*

and files are not excluded. Does anyone know how to overcome it?

like image 558
Dzmitry Kashlach Avatar asked Jul 15 '13 16:07

Dzmitry Kashlach


People also ask

What is a shaded jar?

Shading is a process where a dependency is relocated to a different Java package and copied into the same JAR file as the code that relies on that dependency. The main purpose of shading is to avoid conflicts between the versions of dependencies used by a library and the versions used by the consumers of that library.

What is dependency reduced POM XML?

The dependency-reduced-pom. xml removes transitive dependencies which are already in your shaded jar. This prevents consumers from pulling them in twice.

What is Maven Shade plugin?

This plugin provides the capability to package the artifact in an uber-jar, including its dependencies and to shade - i.e. rename - the packages of some of the dependencies.


2 Answers

Actually you can do global filtering without needing to specify group id, you just need to use the correct wildcard syntax. If you want to exclude all *.RSA files from your jar, for example, specify the artifactId as *:*:*:*

<filters>
    <filter>
        <artifact>*:*:*:*</artifact>
        <excludes>
            <exclude>*.RSA</exclude>
        </excludes>
    </filter>
</filters>
like image 79
Tim Veil Avatar answered Sep 17 '22 14:09

Tim Veil


I had the same problem. It was fixed by making my artifact selector more specific, e.g.

<artifact>bouncycastle:*</artifact>

The entire block looks like this:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-shade-plugin</artifactId>
    <executions>
        <execution>
            <phase>package</phase>
            <goals>
                <goal>shade</goal>
            </goals>
            <configuration>
                <transformers>
                    <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
                        <mainClass>com.mycompany.MainClass</mainClass>
                    </transformer>
                </transformers>
                <filters>
                    <filter>
                        <artifact>bouncycastle:*</artifact>
                        <excludes>
                            <exclude>META-INF/*.SF</exclude>
                            <exclude>META-INF/*.DSA</exclude>
                            <exclude>META-INF/*.RSA</exclude>
                        </excludes>
                    </filter>
                </filters>
                <shadedArtifactAttached>true</shadedArtifactAttached>
                <shadedClassifierName>standalone</shadedClassifierName>
            </configuration>
        </execution>
    </executions>
</plugin>
<plugin>
like image 42
Joe Coder Avatar answered Sep 16 '22 14:09

Joe Coder