Luk
Luk

Reputation: 2246

Install über jar with maven-shaded-plugin

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?

Upvotes: 2

Views: 903

Answers (2)

Dan Coates
Dan Coates

Reputation: 343

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).

Upvotes: 1

khmarbaise
khmarbaise

Reputation: 97409

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>

Upvotes: 3

Related Questions