2

I have been using maven assembly plugin to create uber jar and deploy to Artifactory. I switched to maven shade plugin to shade some dependencies. Now my jar is not deployed during install phase.

In the maven assembly plugin documentation:

When the assembly is created it will use the assemblyId as the artifact's classifier and will attach the created assembly to the project so that it will be uploaded into the repository in the install and deploy phase.

This is not a case for shaded plugin. How to configure maven pom to deploy uber jar created with shaded plugin?

cb4
  • 6,689
  • 7
  • 45
  • 57
Luk
  • 2,186
  • 2
  • 11
  • 32

2 Answers2

3

You have to tell maven-shade-plugin to attach the shaded artifact which can be done via:

<project>
  ...
  <build>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-shade-plugin</artifactId>
        <version>3.2.2</version>
        <executions>
          <execution>
            <phase>package</phase>
            <goals>
              <goal>shade</goal>
            </goals>
            <configuration>
              <shadedArtifactAttached>true</shadedArtifactAttached>
              <shadedClassifierName>jackofall</shadedClassifierName> <!-- Any name that makes sense -->
            </configuration>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>
  ...
</project>
khmarbaise
  • 92,914
  • 28
  • 189
  • 235
  • thank you very much :) this is exactly what I have been looking for :) – Luk Mar 26 '20 at 08:42
  • Use "uber" for the classifier name and the following for modules to use the uber jar as a dependency: abc xyz uber ${project.version} – cb4 May 26 '22 at 19:03
1

I also had this problem, where mvn install would build a shaded jar in my target directory but install the non-shaded one to my local Maven repository.

What ultimately proved to be the cause was that I had <finalName> defined in my maven-shade-plugin configuration. That ended up saving the shaded jar under that specific name, while the non-shaded jar took the default jar name which mvn install must look for when it comes time to install. Without <finalName> present, it copied the shaded jar appropriately into the local Maven repository.

With <shadedArtifactAttached>, I could get the shaded jar installed, but only suffixed with shadedClassifierName while the non-shaded jar was present under the normal artifact name, causing libraries dependent on it to pick up the non-shaded jar over the shaded one (which was not what I wanted in this case as I'm building a library with some dependencies shaded).

Dan Coates
  • 303
  • 2
  • 11