2

following is the structure inside my pom.xml in a multimodule project

Module A pom.xml

<build>
    <plugins>

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-shade-plugin</artifactId>
            <version>2.1</version>
            <configuration>
                <createDependencyReducedPom>true</createDependencyReducedPom>
                <filters>
                    <filter>
                        <artifact>*:*</artifact>
                        <excludes>
                            <exclude>META-INF/*.SF</exclude>
                            <exclude>META-INF/*.DSA</exclude>
                            <exclude>META-INF/*.RSA</exclude>
                        </excludes>
                    </filter>
                </filters>
            </configuration>
            <executions>
                <execution>
                    <phase>package</phase>
                    <goals>
                        <goal>shade</goal>
                    </goals>
                    <configuration>
                        <transformers>
                            <transformer
                                implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer" />
                            <transformer
                                implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
                            </transformer>
                        </transformers>
                    </configuration>
                </execution>
            </executions>
        </plugin>

When I add the maven jar plugin in the build phase in the following way

<plugin>
<artifactId>maven-jar-plugin</artifactId>
<extensions>false</extensions>
<inherited>true</inherited>
<configuration>
   <classifier>project-classifier</classifier>
</configuration>

This gives an error:

Failed to create shaded artifact, project main artifact does not exist.What is the right way to use these plgins together? Should the jar plugin be a part of the parent pom?

user_mda
  • 18,148
  • 27
  • 82
  • 145

1 Answers1

0

The shade plugin expects a non-classified artifact.

Your error should go away if you remove the classifier from your jar plugin configuration:

<configuration>
    <classifier>project-classifier</classifier>
</configuration>

When I had this issue, I chose to add a classifier to the shaded artifact, as seen in the shade plugin documentation

<shadedArtifactAttached>true</shadedArtifactAttached>
<shadedClassifierName>project-classifier</shadedClassifierName>

You will have a base, non-classified jar artifact in your target folder, and a shaded, classified jar. When you run install, it will install both. I chose to ignore the base artifact it didn't cause me any problems. If you want to avoid publishing that, investigate install plugin configuration.

ajk
  • 104
  • 1
  • 7
  • I want to add, there are probably other ways, I have not had the need to explore. you could build the classified jar in a separate project, then reference it in the `artifactSet` element in a second project that does the shading. [shade plugin artifactSet details](https://maven.apache.org/plugins/maven-shade-plugin/shade-mojo.html#artifactSet) – ajk Dec 12 '17 at 14:41