mavenmaven-shade-pluginmaven-install-plugin

How can I mvn:install shaded maven artifact


This should have been easy but I'm experiencing strange behavior from maven-install plug-in.

I needed to repackage some common dependencies into my project to avoid dependency conflicts. for that purpose I used shade plugin with relocations configured:

          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-shade-plugin</artifactId>
            <executions>
                <execution>
                    <id>do_shade</id>
                    <phase>package</phase>
                    <goals>
                        <goal>shade</goal>
                    </goals>
                    <configuration>
                        <createDependencyReducedPom>true</createDependencyReducedPom>
                        <shadedArtifactAttached>false</shadedArtifactAttached>
                        <createSourcesJar>true</createSourcesJar>
                        <relocations>
                            <relocation>
                              <pattern>com.google.common</pattern>
                              <shadedPattern>com.myproject.google.common</shadedPattern>
                            </relocation>
                            <relocation>
                                <pattern>org.apache.commons</pattern>
                                <shadedPattern>com.myproject.commons</shadedPattern>
                            </relocation>
                        </relocations>
                    </configuration>
                </execution>
            </executions>
        </plugin>

The shade plugin did it's job correctly and produced shaded artifact com.myproject-myproject-.jar and dependecy-reduced pom file. But then install plugin installed the original artifact (without dependencies) instead of the shaded one.

Further more, before that install plugin problem my CI server (jenkins) built the project and correctly published the shaded artifact and dependency reduced pom to nexus repository (!!). So now it I download the artifact from nexus, i'll have correct jars in my local repository, but if I use install plugin, the jars won't be good.

Has anyone had similar issues? Does anyone know how to resolve them??


Solution

  • To answer my own question, the problem was that I later marked the dependencies-to-be-shaded as provided so that they don't get transitively pulled into my other projects. That caused shade plugin to not include them in shaded jar.