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 <[email protected]>
Sent: Saturday, March 16, 2019 5:34 AM
To: [email protected]
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

[email protected]<mailto:[email protected]>
 ~/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>

[email protected]<mailto:[email protected]>
 ~/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>

[email protected]<mailto:[email protected]>
 ~/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

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

[email protected]<mailto:[email protected]>
 ~/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

[email protected]<mailto:[email protected]>
 ~/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

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

[email protected]<mailto:[email protected]>
 ~/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

[email protected]<mailto:[email protected]>
 ~/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 via email to