maven-shade-plugin : uber-jar remains empty

17 Views Asked by At

I have a spring project that depends on some java projects that are package under jboss-sar. My project use maven to manage the dependencies. After building the project, when I run the application it fails with many ClassNotFound errors because it cannot find the classes of the jboss-sar projects.

To solve this issue I try since a while now to build and install a uber-jar with maven-shade-plugin. I used 3 plugins maven to first extract the classes from the jboss-sar projects and copy them to a repository jboss-sar-classes. Then with the maven-shade-plugin I try to package the content of this directory into a uber-jar, and finally I install the jar created locally.

This allow me to put a new dependency to the uber-jar in my pom and to have no error in my code and to include the classes in the output of the Spring application.

When I was doing that in the part of the pom (in the main part of the pom) it was working fine. The uber-jar was containing exactly the classes I needed.

Now I faced a problem : when the uber-jar is not yet installed the first time, the dependency on it make the mvn clean install of the whole pom to fail because of missing dependency.

To solve that I created a default profile that include the dependency with the uber-jar inside the profile only. And I created another specific profile which I only use to build the uber-jar and install it.

This is the profile :

<profile>
        <id>build-uber-jar</id>
        <build>
            <plugins>
                <!-- Specific for sar dependencies -->
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-dependency-plugin</artifactId>
                    <executions>
                        <execution>
                            <id>copy-dependency-classes</id>
                            <phase>package</phase>
                            <goals>
                                <goal>unpack-dependencies</goal>
                            </goals>
                        </execution>
                    </executions>
                    <configuration>
                        <includeTypes>jboss-sar</includeTypes>
                        <outputDirectory>${project.build.directory}/jboss-sar-classes</outputDirectory>
                    </configuration>
                </plugin>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-shade-plugin</artifactId>
                    <executions>
                        <execution>
                            <phase>package</phase>
                            <goals>
                                <goal>shade</goal>
                            </goals>
                        </execution>
                    </executions>
                    <configuration>
                        <outputFile>${project.build.directory}/${trace-sar-name}-${project.version}.jar</outputFile>
                        <filters>
                            <filter>
                                <artifact>*</artifact>
                                <excludes>
                                    <exclude>**</exclude>
                                    <exclude>META-INF/*.SF</exclude>
                                    <exclude>META-INF/*.DSA</exclude>
                                    <exclude>META-INF/*.RSA</exclude>
                                </excludes>
                            </filter>
                        </filters>
                        <transformers>
                            <transformer implementation="org.apache.maven.plugins.shade.resource.IncludeResourceTransformer">
                                <resource>${project.build.directory}/jboss-sar-classes/**</resource>
                            </transformer>
                            <transformer implementation="org.apache.maven.plugins.shade.resource.ResourceBundleAppendingTransformer">
                                <!-- the base name of the resource bundle, a fully qualified class name -->
                                <resource>jboss-sar-classes</resource>
                            </transformer>
                        </transformers>
                        <shadedArtifactAttached>true</shadedArtifactAttached>
                        <shadedClassifierName>uber</shadedClassifierName>
                    </configuration>
                </plugin>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-install-plugin</artifactId>
                    <executions>
                        <execution>
                            <phase>package</phase>
                            <goals>
                                <goal>install-file</goal>
                            </goals>
                        </execution>
                    </executions>
                    <configuration>
                        <file>${project.build.directory}/${trace-sar-name}-${project.version}.jar</file>
                        <groupId>${project.groupId}</groupId>
                        <artifactId>${trace-sar-name}</artifactId>
                        <version>${project.version}</version>
                        <packaging>jar</packaging>
                    </configuration>
                </plugin>
            </plugins>
        </build>
    </profile>

But now the uber-jar is empty. no classes are copied inside and the jar weight is 1Ko. If I remove the exclusion, instead of copiing the content of the directory jboss-sar-classes it copies the classes of all the main dependencies and the final jar weight is 95Mo which is not good.

The question is why now that I moved the building of the uber-jar into a profile, it doesn't manage to copy the content of directory?

0

There are 0 best solutions below