Usage of dependency-reduced-pom.xml from maven-shade-plugin in a multi-module/reactor project

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

Usage of dependency-reduced-pom.xml from maven-shade-plugin in a multi-module/reactor project

Kyle Marek

I am having a dependency conflict issue in a project I am working on.

Specifically, a dependency of a dependency of a dependency depends on Jersey 1.9 for internal client purposes, while I am using Jersey 2.28 in implementing a REST interface for the high level functionality of the project. Since Jersey 1.9 is basically being used invisibly and behind the scenes inside of my dependency, I am attempting to use maven-shade-plugin to include the dependency and Jersey 1.9 and relocate Jersey to another package while I use Jersey 2.28 up front in its original package.

maven-shade-plugin creates a modified POM file with reduced dependencies for installation so dependent projects won't pull in dependencies for the jar when they are already included/shaded in the jar.

However, what I am finding is that when the functional component and the web application component of the project are developed as *modules* to an aggregating/parent POM, the build process only accounts for the *original* POM of the shaded functional module with its original/pre-reduced dependencies, which makes the build of the web application module pull in the original dependencies, that should have been shaded, into its WEB-INF/lib/. The dependency management works correctly when installing the shaded functional component, and building the web application module independently.

Is this a bug or by design? Is there a proper fix to apply to my POM files, or am I stuck ordering, building and installing each project independently for now?

My test case and details follow. Please note that I am demonstrating the issue and left relocations and artifact includes/excludes out of the maven-shade-plugin configuration.

See:

# POM files

[hidden email] ~/src/shadetest
$ cat pom.xml
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
  <modelVersion>4.0.0</modelVersion>

  <groupId>net.gigabyteproductions.maven.shadetest</groupId>
  <artifactId>shadetest-parent</artifactId>
  <packaging>pom</packaging>
  <version>1.0-SNAPSHOT</version>

  <modules>
    <module>lib</module>
    <module>service</module>
  </modules>

  <dependencyManagement>
    <dependencies>
      <dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>servlet-api</artifactId>
        <version>2.5</version>
        <scope>provided</scope>
      </dependency>
      <dependency>
        <groupId>org.apache.accumulo</groupId>
        <artifactId>accumulo-core</artifactId>
        <version>1.8.1</version>
      </dependency>
    </dependencies>
  </dependencyManagement>

  <build>
    <pluginManagement>
      <plugins>
        <plugin>
          <groupId>org.apache.maven.plugins</groupId>
          <artifactId>maven-shade-plugin</artifactId>
          <version>3.0.0</version>
        </plugin>
        <plugin>
          <groupId>org.apache.tomcat.maven</groupId>
          <artifactId>tomcat7-maven-plugin</artifactId>
          <version>2.2</version>
        </plugin>
      </plugins>
    </pluginManagement>
  </build>

</project>

[hidden email] ~/src/shadetest
$ cat lib/pom.xml
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
  <modelVersion>4.0.0</modelVersion>

  <parent>
    <groupId>net.gigabyteproductions.maven.shadetest</groupId>
    <artifactId>shadetest-parent</artifactId>
    <version>1.0-SNAPSHOT</version>
    <relativePath>..</relativePath>
  </parent>

  <artifactId>shadetest-lib</artifactId>
  <packaging>jar</packaging>
  <version>1.0-SNAPSHOT</version>

  <dependencies>
    <dependency>
      <groupId>org.apache.accumulo</groupId>
      <artifactId>accumulo-core</artifactId>
    </dependency>
  </dependencies>

  <build>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-shade-plugin</artifactId>
        <executions>
          <execution>
            <phase>package</phase>
            <goals>
              <goal>shade</goal>
            </goals>
            <configuration>
<!--
              <dependencyReducedPomLocation>${project.build.directory}/dependency-reduced-pom.xml</dependencyReducedPomLocation>
-->
              <shadedArtifactAttached>false</shadedArtifactAttached>
              <transformers>
                <transformer implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer"/>
              </transformers>
            </configuration>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>

</project>

[hidden email] ~/src/shadetest
$ cat service/pom.xml
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
  <modelVersion>4.0.0</modelVersion>

  <parent>
    <groupId>net.gigabyteproductions.maven.shadetest</groupId>
    <artifactId>shadetest-parent</artifactId>
    <version>1.0-SNAPSHOT</version>
    <relativePath>..</relativePath>
  </parent>

  <artifactId>shadetest-service</artifactId>
  <packaging>war</packaging>
  <version>1.0-SNAPSHOT</version>

  <dependencies>
    <dependency>
      <groupId>net.gigabyteproductions.maven.shadetest</groupId>
      <artifactId>shadetest-lib</artifactId>
      <version>1.0-SNAPSHOT</version>
    </dependency>
    <dependency>
      <groupId>org.glassfish.jersey.containers</groupId>
      <artifactId>jersey-container-servlet-core</artifactId>
      <version>2.28</version>
    </dependency>
    <dependency>
      <groupId>org.glassfish.jersey.inject</groupId>
      <artifactId>jersey-hk2</artifactId>
      <version>2.28</version>
    </dependency>
  </dependencies>

</project>


# reactor build/install

[hidden email] ~/src/shadetest
$ rm -rf ~/.m2/repository/net/gigabyteproductions/maven/shadetest/

[hidden email] ~/src/shadetest
$ mvn clean install
[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Build Order:
[INFO] 
[INFO] shadetest-parent                                                   [pom]
[INFO] shadetest-lib                                                      [jar]
[INFO] shadetest-service                                                  [war]
. . .
[INFO] --- maven-shade-plugin:3.0.0:shade (default) @ shadetest-lib ---
[INFO] Including org.apache.accumulo:accumulo-core:jar:1.8.1 in the shaded jar.
. . .
[INFO] Including com.sun.jersey:jersey-core:jar:1.9 in the shaded jar.
[INFO] Including com.sun.jersey:jersey-client:jar:1.9 in the shaded jar.
. . .
[INFO] Replacing original artifact with shaded artifact.
[INFO] Replacing /home/kmarek/src/shadetest/lib/target/shadetest-lib-1.0-SNAPSHOT.jar with /home/kmarek/src/shadetest/lib/target/shadetest-lib-1.0-SNAPSHOT-shaded.jar
[INFO] Dependency-reduced POM written at: /home/kmarek/src/shadetest/lib/dependency-reduced-pom.xml
[INFO] 
[INFO] --- maven-install-plugin:2.4:install (default-install) @ shadetest-lib ---
[INFO] Installing /home/kmarek/src/shadetest/lib/target/shadetest-lib-1.0-SNAPSHOT.jar to /home/kmarek/.m2/repository/net/gigabyteproductions/maven/shadetest/shadetest-lib/1.0-SNAPSHOT/shadetest-lib-1.0-SNAPSHOT.jar
[INFO] Installing /home/kmarek/src/shadetest/lib/dependency-reduced-pom.xml to /home/kmarek/.m2/repository/net/gigabyteproductions/maven/shadetest/shadetest-lib/1.0-SNAPSHOT/shadetest-lib-1.0-SNAPSHOT.pom
. . .
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary:
[INFO] 
[INFO] shadetest-parent 1.0-SNAPSHOT ...................... SUCCESS [  0.264 s]
[INFO] shadetest-lib ...................................... SUCCESS [  5.587 s]
[INFO] shadetest-service 1.0-SNAPSHOT ..................... SUCCESS [  5.087 s]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 11.045 s
[INFO] Finished at: 2019-03-16T00:44:39-04:00
[INFO] ------------------------------------------------------------------------


# Notice the original Accumulo and Jersey dependencies of the lib module were
# pulled into the service module, in addition to the shaded lib module
# artifact

[hidden email] ~/src/shadetest
$ ls -1 service/target/shadetest-service-1.0-SNAPSHOT/WEB-INF/lib/
accumulo-core-1.8.1.jar
accumulo-fate-1.8.1.jar
accumulo-start-1.8.1.jar
activation-1.1.jar
aopalliance-repackaged-2.5.0.jar
apacheds-i18n-2.0.0-M15.jar
apacheds-kerberos-codec-2.0.0-M15.jar
api-asn1-api-1.0.0-M20.jar
api-util-1.0.0-M20.jar
avro-1.7.4.jar
commons-beanutils-1.7.0.jar
commons-beanutils-core-1.8.0.jar
commons-cli-1.2.jar
commons-codec-1.4.jar
commons-collections-3.2.2.jar
commons-compress-1.4.1.jar
commons-configuration-1.6.jar
commons-digester-1.8.jar
commons-httpclient-3.1.jar
commons-io-2.4.jar
commons-lang-2.4.jar
commons-logging-1.1.1.jar
commons-math3-3.6.1.jar
commons-net-3.1.jar
commons-vfs2-2.1.jar
curator-client-2.6.0.jar
curator-framework-2.6.0.jar
curator-recipes-2.6.0.jar
gson-2.2.4.jar
guava-14.0.1.jar
hadoop-annotations-2.6.4.jar
hadoop-auth-2.6.4.jar
hadoop-client-2.6.4.jar
hadoop-common-2.6.4.jar
hadoop-hdfs-2.6.4.jar
hadoop-mapreduce-client-app-2.6.4.jar
hadoop-mapreduce-client-common-2.6.4.jar
hadoop-mapreduce-client-core-2.6.4.jar
hadoop-mapreduce-client-jobclient-2.6.4.jar
hadoop-mapreduce-client-shuffle-2.6.4.jar
hadoop-yarn-api-2.6.4.jar
hadoop-yarn-client-2.6.4.jar
hadoop-yarn-common-2.6.4.jar
hadoop-yarn-server-common-2.6.4.jar
hk2-api-2.5.0.jar
hk2-locator-2.5.0.jar
hk2-utils-2.5.0.jar
htrace-core-3.0.4.jar
htrace-core-3.1.0-incubating.jar
httpclient-4.2.5.jar
httpcore-4.2.4.jar
jackson-core-asl-1.9.13.jar
jackson-jaxrs-1.9.13.jar
jackson-mapper-asl-1.9.13.jar
jackson-xc-1.9.13.jar
jakarta.annotation-api-1.3.4.jar
jakarta.inject-2.5.0.jar
jakarta.ws.rs-api-2.1.5.jar
javassist-3.22.0-CR2.jar
jaxb-api-2.2.2.jar
jcommander-1.48.jar
jersey-client-1.9.jar
jersey-client-2.28.jar
jersey-common-2.28.jar
jersey-container-servlet-core-2.28.jar
jersey-core-1.9.jar
jersey-hk2-2.28.jar
jersey-media-jaxb-2.28.jar
jersey-server-2.28.jar
jetty-util-6.1.26.jar
jline-2.11.jar
jsr305-1.3.9.jar
leveldbjni-all-1.8.jar
libthrift-0.9.3.jar
log4j-1.2.17.jar
netty-3.7.0.Final.jar
osgi-resource-locator-1.0.1.jar
paranamer-2.3.jar
protobuf-java-2.5.0.jar
shadetest-lib-1.0-SNAPSHOT.jar
slf4j-api-1.7.21.jar
slf4j-log4j12-1.6.1.jar
snappy-java-1.0.4.1.jar
stax-api-1.0-2.jar
validation-api-2.0.1.Final.jar
xercesImpl-2.9.1.jar
xml-apis-1.3.04.jar
xmlenc-0.52.jar
xz-1.0.jar
zookeeper-3.4.6.jar


# Independent build of the service module

[hidden email] ~/src/shadetest
$ cd service

[hidden email] ~/src/shadetest/service
$ mvn clean install
. . .
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 3.662 s
[INFO] Finished at: 2019-03-16T00:45:04-04:00
[INFO] ------------------------------------------------------------------------


# Notice the dependencies are reduced to its own dependencies and the shaded
# lib module artifact

[hidden email] ~/src/shadetest/service
$ ls -1 target/shadetest-service-1.0-SNAPSHOT/WEB-INF/lib/
aopalliance-repackaged-2.5.0.jar
hk2-api-2.5.0.jar
hk2-locator-2.5.0.jar
hk2-utils-2.5.0.jar
jakarta.annotation-api-1.3.4.jar
jakarta.inject-2.5.0.jar
jakarta.ws.rs-api-2.1.5.jar
javassist-3.22.0-CR2.jar
jersey-client-2.28.jar
jersey-common-2.28.jar
jersey-container-servlet-core-2.28.jar
jersey-hk2-2.28.jar
jersey-media-jaxb-2.28.jar
jersey-server-2.28.jar
osgi-resource-locator-1.0.1.jar
shadetest-lib-1.0-SNAPSHOT.jar
validation-api-2.0.1.Final.jar


signature.asc (849 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Usage of dependency-reduced-pom.xml from maven-shade-plugin in a multi-module/reactor project

Nikki Novak
Wolf helped me out with a similar issue.

https://github.com/BattlePlugins/BattleBukkitLib/issues/3


He alerted me to the Maven-Flatten-Plugin:

https://www.mojohaus.org/flatten-maven-plugin/

Quote:
"This essentially allows you to use your parent POMs during builds but
deletes the reference to them when your artifact gets deployed,
integrating the information from the parents at the appropriate places
(flattening), reducing the information "leaked" to the consumer of your
artifact to the bare minimum."  ~Wolf

Hopefully that can help solve your issue as well.

As for some of your technical questions about the behavior of Maven, we're in the same boat.

There are some aspects of Maven that I don't quite understand... but I am extremely curious.

Good luck !
Nick


________________________________
From: Kyle Marek <[hidden email]>
Sent: Saturday, March 16, 2019 5:34 AM
To: [hidden email]
Subject: Usage of dependency-reduced-pom.xml from maven-shade-plugin in a multi-module/reactor project


I am having a dependency conflict issue in a project I am working on.

Specifically, a dependency of a dependency of a dependency depends on Jersey 1.9 for internal client purposes, while I am using Jersey 2.28 in implementing a REST interface for the high level functionality of the project. Since Jersey 1.9 is basically being used invisibly and behind the scenes inside of my dependency, I am attempting to use maven-shade-plugin to include the dependency and Jersey 1.9 and relocate Jersey to another package while I use Jersey 2.28 up front in its original package.

maven-shade-plugin creates a modified POM file with reduced dependencies for installation so dependent projects won't pull in dependencies for the jar when they are already included/shaded in the jar.

However, what I am finding is that when the functional component and the web application component of the project are developed as *modules* to an aggregating/parent POM, the build process only accounts for the *original* POM of the shaded functional module with its original/pre-reduced dependencies, which makes the build of the web application module pull in the original dependencies, that should have been shaded, into its WEB-INF/lib/. The dependency management works correctly when installing the shaded functional component, and building the web application module independently.

Is this a bug or by design? Is there a proper fix to apply to my POM files, or am I stuck ordering, building and installing each project independently for now?

My test case and details follow. Please note that I am demonstrating the issue and left relocations and artifact includes/excludes out of the maven-shade-plugin configuration.

See:

# POM files

[hidden email]<mailto:[hidden email]> ~/src/shadetest
$ cat pom.xml
<project xmlns="http://maven.apache.org/POM/4.0.0"<http://maven.apache.org/POM/4.0.0> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"<http://www.w3.org/2001/XMLSchema-instance>
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"<http://maven.apache.org/POM/4.0.0http://maven.apache.org/maven-v4_0_0.xsd>>
  <modelVersion>4.0.0</modelVersion>

  <groupId>net.gigabyteproductions.maven.shadetest</groupId>
  <artifactId>shadetest-parent</artifactId>
  <packaging>pom</packaging>
  <version>1.0-SNAPSHOT</version>

  <modules>
    <module>lib</module>
    <module>service</module>
  </modules>

  <dependencyManagement>
    <dependencies>
      <dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>servlet-api</artifactId>
        <version>2.5</version>
        <scope>provided</scope>
      </dependency>
      <dependency>
        <groupId>org.apache.accumulo</groupId>
        <artifactId>accumulo-core</artifactId>
        <version>1.8.1</version>
      </dependency>
    </dependencies>
  </dependencyManagement>

  <build>
    <pluginManagement>
      <plugins>
        <plugin>
          <groupId>org.apache.maven.plugins</groupId>
          <artifactId>maven-shade-plugin</artifactId>
          <version>3.0.0</version>
        </plugin>
        <plugin>
          <groupId>org.apache.tomcat.maven</groupId>
          <artifactId>tomcat7-maven-plugin</artifactId>
          <version>2.2</version>
        </plugin>
      </plugins>
    </pluginManagement>
  </build>

</project>

[hidden email]<mailto:[hidden email]> ~/src/shadetest
$ cat lib/pom.xml
<project xmlns="http://maven.apache.org/POM/4.0.0"<http://maven.apache.org/POM/4.0.0> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"<http://www.w3.org/2001/XMLSchema-instance>
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"<http://maven.apache.org/POM/4.0.0http://maven.apache.org/maven-v4_0_0.xsd>>
  <modelVersion>4.0.0</modelVersion>

  <parent>
    <groupId>net.gigabyteproductions.maven.shadetest</groupId>
    <artifactId>shadetest-parent</artifactId>
    <version>1.0-SNAPSHOT</version>
    <relativePath>..</relativePath>
  </parent>

  <artifactId>shadetest-lib</artifactId>
  <packaging>jar</packaging>
  <version>1.0-SNAPSHOT</version>

  <dependencies>
    <dependency>
      <groupId>org.apache.accumulo</groupId>
      <artifactId>accumulo-core</artifactId>
    </dependency>
  </dependencies>

  <build>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-shade-plugin</artifactId>
        <executions>
          <execution>
            <phase>package</phase>
            <goals>
              <goal>shade</goal>
            </goals>
            <configuration>
<!--
              <dependencyReducedPomLocation>${project.build.directory}/dependency-reduced-pom.xml</dependencyReducedPomLocation>
-->
              <shadedArtifactAttached>false</shadedArtifactAttached>
              <transformers>
                <transformer implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer"/>
              </transformers>
            </configuration>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>

</project>

[hidden email]<mailto:[hidden email]> ~/src/shadetest
$ cat service/pom.xml
<project xmlns="http://maven.apache.org/POM/4.0.0"<http://maven.apache.org/POM/4.0.0> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"<http://www.w3.org/2001/XMLSchema-instance>
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"<http://maven.apache.org/POM/4.0.0http://maven.apache.org/maven-v4_0_0.xsd>>
  <modelVersion>4.0.0</modelVersion>

  <parent>
    <groupId>net.gigabyteproductions.maven.shadetest</groupId>
    <artifactId>shadetest-parent</artifactId>
    <version>1.0-SNAPSHOT</version>
    <relativePath>..</relativePath>
  </parent>

  <artifactId>shadetest-service</artifactId>
  <packaging>war</packaging>
  <version>1.0-SNAPSHOT</version>

  <dependencies>
    <dependency>
      <groupId>net.gigabyteproductions.maven.shadetest</groupId>
      <artifactId>shadetest-lib</artifactId>
      <version>1.0-SNAPSHOT</version>
    </dependency>
    <dependency>
      <groupId>org.glassfish.jersey.containers</groupId>
      <artifactId>jersey-container-servlet-core</artifactId>
      <version>2.28</version>
    </dependency>
    <dependency>
      <groupId>org.glassfish.jersey.inject</groupId>
      <artifactId>jersey-hk2</artifactId>
      <version>2.28</version>
    </dependency>
  </dependencies>

</project>


# reactor build/install

[hidden email]<mailto:[hidden email]> ~/src/shadetest
$ rm -rf ~/.m2/repository/net/gigabyteproductions/maven/shadetest/

[hidden email]<mailto:[hidden email]> ~/src/shadetest
$ mvn clean install
[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Build Order:
[INFO]
[INFO] shadetest-parent                                                   [pom]
[INFO] shadetest-lib                                                      [jar]
[INFO] shadetest-service                                                  [war]
. . .
[INFO] --- maven-shade-plugin:3.0.0:shade (default) @ shadetest-lib ---
[INFO] Including org.apache.accumulo:accumulo-core:jar:1.8.1 in the shaded jar.
. . .
[INFO] Including com.sun.jersey:jersey-core:jar:1.9 in the shaded jar.
[INFO] Including com.sun.jersey:jersey-client:jar:1.9 in the shaded jar.
. . .
[INFO] Replacing original artifact with shaded artifact.
[INFO] Replacing /home/kmarek/src/shadetest/lib/target/shadetest-lib-1.0-SNAPSHOT.jar with /home/kmarek/src/shadetest/lib/target/shadetest-lib-1.0-SNAPSHOT-shaded.jar
[INFO] Dependency-reduced POM written at: /home/kmarek/src/shadetest/lib/dependency-reduced-pom.xml
[INFO]
[INFO] --- maven-install-plugin:2.4:install (default-install) @ shadetest-lib ---
[INFO] Installing /home/kmarek/src/shadetest/lib/target/shadetest-lib-1.0-SNAPSHOT.jar to /home/kmarek/.m2/repository/net/gigabyteproductions/maven/shadetest/shadetest-lib/1.0-SNAPSHOT/shadetest-lib-1.0-SNAPSHOT.jar
[INFO] Installing /home/kmarek/src/shadetest/lib/dependency-reduced-pom.xml to /home/kmarek/.m2/repository/net/gigabyteproductions/maven/shadetest/shadetest-lib/1.0-SNAPSHOT/shadetest-lib-1.0-SNAPSHOT.pom
. . .
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary:
[INFO]
[INFO] shadetest-parent 1.0-SNAPSHOT ...................... SUCCESS [  0.264 s]
[INFO] shadetest-lib ...................................... SUCCESS [  5.587 s]
[INFO] shadetest-service 1.0-SNAPSHOT ..................... SUCCESS [  5.087 s]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 11.045 s
[INFO] Finished at: 2019-03-16T00:44:39-04:00
[INFO] ------------------------------------------------------------------------


# Notice the original Accumulo and Jersey dependencies of the lib module were
# pulled into the service module, in addition to the shaded lib module
# artifact

[hidden email]<mailto:[hidden email]> ~/src/shadetest
$ ls -1 service/target/shadetest-service-1.0-SNAPSHOT/WEB-INF/lib/
accumulo-core-1.8.1.jar
accumulo-fate-1.8.1.jar
accumulo-start-1.8.1.jar
activation-1.1.jar
aopalliance-repackaged-2.5.0.jar
apacheds-i18n-2.0.0-M15.jar
apacheds-kerberos-codec-2.0.0-M15.jar
api-asn1-api-1.0.0-M20.jar
api-util-1.0.0-M20.jar
avro-1.7.4.jar
commons-beanutils-1.7.0.jar
commons-beanutils-core-1.8.0.jar
commons-cli-1.2.jar
commons-codec-1.4.jar
commons-collections-3.2.2.jar
commons-compress-1.4.1.jar
commons-configuration-1.6.jar
commons-digester-1.8.jar
commons-httpclient-3.1.jar
commons-io-2.4.jar
commons-lang-2.4.jar
commons-logging-1.1.1.jar
commons-math3-3.6.1.jar
commons-net-3.1.jar
commons-vfs2-2.1.jar
curator-client-2.6.0.jar
curator-framework-2.6.0.jar
curator-recipes-2.6.0.jar
gson-2.2.4.jar
guava-14.0.1.jar
hadoop-annotations-2.6.4.jar
hadoop-auth-2.6.4.jar
hadoop-client-2.6.4.jar
hadoop-common-2.6.4.jar
hadoop-hdfs-2.6.4.jar
hadoop-mapreduce-client-app-2.6.4.jar
hadoop-mapreduce-client-common-2.6.4.jar
hadoop-mapreduce-client-core-2.6.4.jar
hadoop-mapreduce-client-jobclient-2.6.4.jar
hadoop-mapreduce-client-shuffle-2.6.4.jar
hadoop-yarn-api-2.6.4.jar
hadoop-yarn-client-2.6.4.jar
hadoop-yarn-common-2.6.4.jar
hadoop-yarn-server-common-2.6.4.jar
hk2-api-2.5.0.jar
hk2-locator-2.5.0.jar
hk2-utils-2.5.0.jar
htrace-core-3.0.4.jar
htrace-core-3.1.0-incubating.jar
httpclient-4.2.5.jar
httpcore-4.2.4.jar
jackson-core-asl-1.9.13.jar
jackson-jaxrs-1.9.13.jar
jackson-mapper-asl-1.9.13.jar
jackson-xc-1.9.13.jar
jakarta.annotation-api-1.3.4.jar
jakarta.inject-2.5.0.jar
jakarta.ws.rs-api-2.1.5.jar
javassist-3.22.0-CR2.jar
jaxb-api-2.2.2.jar
jcommander-1.48.jar
jersey-client-1.9.jar
jersey-client-2.28.jar
jersey-common-2.28.jar
jersey-container-servlet-core-2.28.jar
jersey-core-1.9.jar
jersey-hk2-2.28.jar
jersey-media-jaxb-2.28.jar
jersey-server-2.28.jar
jetty-util-6.1.26.jar
jline-2.11.jar
jsr305-1.3.9.jar
leveldbjni-all-1.8.jar
libthrift-0.9.3.jar
log4j-1.2.17.jar
netty-3.7.0.Final.jar
osgi-resource-locator-1.0.1.jar
paranamer-2.3.jar
protobuf-java-2.5.0.jar
shadetest-lib-1.0-SNAPSHOT.jar
slf4j-api-1.7.21.jar
slf4j-log4j12-1.6.1.jar
snappy-java-1.0.4.1.jar
stax-api-1.0-2.jar
validation-api-2.0.1.Final.jar
xercesImpl-2.9.1.jar
xml-apis-1.3.04.jar
xmlenc-0.52.jar
xz-1.0.jar
zookeeper-3.4.6.jar


# Independent build of the service module

[hidden email]<mailto:[hidden email]> ~/src/shadetest
$ cd service

[hidden email]<mailto:[hidden email]> ~/src/shadetest/service
$ mvn clean install
. . .
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 3.662 s
[INFO] Finished at: 2019-03-16T00:45:04-04:00
[INFO] ------------------------------------------------------------------------


# Notice the dependencies are reduced to its own dependencies and the shaded
# lib module artifact

[hidden email]<mailto:[hidden email]> ~/src/shadetest/service
$ ls -1 target/shadetest-service-1.0-SNAPSHOT/WEB-INF/lib/
aopalliance-repackaged-2.5.0.jar
hk2-api-2.5.0.jar
hk2-locator-2.5.0.jar
hk2-utils-2.5.0.jar
jakarta.annotation-api-1.3.4.jar
jakarta.inject-2.5.0.jar
jakarta.ws.rs-api-2.1.5.jar
javassist-3.22.0-CR2.jar
jersey-client-2.28.jar
jersey-common-2.28.jar
jersey-container-servlet-core-2.28.jar
jersey-hk2-2.28.jar
jersey-media-jaxb-2.28.jar
jersey-server-2.28.jar
osgi-resource-locator-1.0.1.jar
shadetest-lib-1.0-SNAPSHOT.jar
validation-api-2.0.1.Final.jar


Reply | Threaded
Open this post in threaded view
|

Re: Usage of dependency-reduced-pom.xml from maven-shade-plugin in a multi-module/reactor project

Francois MAROT
In reply to this post by Kyle Marek
Hello Kyle,

to my knowledge your analysis is good, you are correct.
Sorry but I did not take the time to read your pom excerpt but I have been
using the shade plugin for quite some time now and concluded that shaded
artifacts must be leafs in the Maven modules tree. By "leaf" I mean no
artifact in the same Maven reactor must depend upon a shaded artifact. You
must separate the build of a shaded artifact and those depending upon it.

From my understanding, this relates to the way Maven calculates the
dependencies: they are calculated at the beginning of the build, not at the
end or incrementally. While the shade plugin acts merely as a hack and
replaces the pom at the end of building the shaded module. It's too late  in
the process as the dependencies of artifacts depending on the shaded one
have already been calculated.

My advice would be to ensure you have 2 separated projects, not part of the
same reactor build to prevent problems or surprise for newcomers.

Regards
Francois Marot



--
Sent from: http://maven.40175.n5.nabble.com/Maven-Users-f40176.html

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: Usage of dependency-reduced-pom.xml from maven-shade-plugin in a multi-module/reactor project

Nikki Novak
Francois,

Oh wow, I never knew shaded modules should be leafs... thanks!

...two separate projects ?

Conceptually, I always thought of each module as its own project.
I guess that's the wrong way of thinking about modules ?

What about doing a reactor of reactors ?
Would that be a sufficient work-around ?
Would that satisfy the separate-projects rule ?
Or no ?

Thanks,
Nick


________________________________
From: Francois MAROT <[hidden email]>
Sent: Sunday, March 17, 2019 10:38 PM
To: [hidden email]
Subject: Re: Usage of dependency-reduced-pom.xml from maven-shade-plugin in a multi-module/reactor project

Hello Kyle,

to my knowledge your analysis is good, you are correct.
Sorry but I did not take the time to read your pom excerpt but I have been
using the shade plugin for quite some time now and concluded that shaded
artifacts must be leafs in the Maven modules tree. By "leaf" I mean no
artifact in the same Maven reactor must depend upon a shaded artifact. You
must separate the build of a shaded artifact and those depending upon it.

From my understanding, this relates to the way Maven calculates the
dependencies: they are calculated at the beginning of the build, not at the
end or incrementally. While the shade plugin acts merely as a hack and
replaces the pom at the end of building the shaded module. It's too late  in
the process as the dependencies of artifacts depending on the shaded one
have already been calculated.

My advice would be to ensure you have 2 separated projects, not part of the
same reactor build to prevent problems or surprise for newcomers.

Regards
Francois Marot



--
Sent from: http://maven.40175.n5.nabble.com/Maven-Users-f40176.html

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: Usage of dependency-reduced-pom.xml from maven-shade-plugin in a multi-module/reactor project

Francois MAROT
Hi Nikki,

Regarding your question, I'm not sure of what is a "reactor of reactor"...
by 2 separate "projects" I mean 2 different build. Hence 2 different
"reactor".
As I understand it, the reactor is the sum of all Maven modules
participating in the build. Usually in the case of a multi-modules Maven
project, you start the build from the top level module, and all your modules
are part of the same rector. Part of the same build.
I personally like to have one git repository per multi-module Maven project
so we have:

1 git repo --> containing one multi-modules Maven project ⊃ composed of many
modules == one build == one reactor

What is sure is that for the shade plugin to work, you have to make Maven
builds depending on the shaded artifact find this artifact stored in a repo
(whether local or remote) and not reference it as a module inside the
reactor (ie part of the same build).

I hope it helps !



--
Sent from: http://maven.40175.n5.nabble.com/Maven-Users-f40176.html

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: Usage of dependency-reduced-pom.xml from maven-shade-plugin in a multi-module/reactor project

Kyle Marek
Building the shaded module separately was my workaround for a few days.
My current workaround is to specify the intra-module dependency in my
parent pom under dependencyManagement with a list of exclusions for the
artifacts I am shading into it. Effectively I am manually "reducing" the
dependency set of the shaded module as seen from within the multi-module
project.

However, I think it might be best for Maven to (re-)allow the set of
dependencies listed to reduce after build due to plugins like
maven-shade-plugin. While needing to shade in general is not ideal,
needing to build the module outside of the reactor in addition to
shading is less ideal, especially in a larger project where it may need
to be ordered between other modules to successfully build.

See: https://issues.apache.org/jira/browse/MSHADE-206
See: https://issues.apache.org/jira/browse/MNG-5899

On 3/18/19 5:12 PM, Francois MAROT wrote:

> Hi Nikki,
>
> Regarding your question, I'm not sure of what is a "reactor of reactor"...
> by 2 separate "projects" I mean 2 different build. Hence 2 different
> "reactor".
> As I understand it, the reactor is the sum of all Maven modules
> participating in the build. Usually in the case of a multi-modules Maven
> project, you start the build from the top level module, and all your modules
> are part of the same rector. Part of the same build.
> I personally like to have one git repository per multi-module Maven project
> so we have:
>
> 1 git repo --> containing one multi-modules Maven project ⊃ composed of many
> modules == one build == one reactor
>
> What is sure is that for the shade plugin to work, you have to make Maven
> builds depending on the shaded artifact find this artifact stored in a repo
> (whether local or remote) and not reference it as a module inside the
> reactor (ie part of the same build).
>
> I hope it helps !


signature.asc (849 bytes) Download Attachment