Hi All

I've run into what seems like an odd bug where the Shade plugin apparently gets 
stuck in an infinite loop when attempting to produce the Dependency Reduced POM 
(DRP).  For now as a hack I've turned off generation of the DRP for my affected 
project because it is unlikely that the artifact being produced will be pulled 
in via Maven so having a POM still reference all the dependencies is not a huge 
issue for me.

However I have attempted to produce a minimal test case and debug this a 
little, hopefully someone more familiar with the plugin can dig into this 
further and figure out whether this is a bug and how to fix it in future 
versions of the plugin.

Here is a minimal POM that reproduces the problem:


<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/xsd/maven-4.0.0.xsd";>

<modelVersion>4.0.0</modelVersion>

<groupId>org.example</groupId>

<artifactId>shade-dpr-bug</artifactId>

<version>0.0.1-SNAPSHOT</version>

<name>Maven Shade DPR Bug Demonstrator</name>

<description>Repro for an apparent bug discovered in Maven Shade 
plugin</description>

<dependencies>

<dependency>

<groupId>org.apache.jena</groupId>

<artifactId>jena-arq</artifactId>

<version>2.10.1</version>

</dependency>

<!-- If you comment out either of the following dependency then things will 
work fine -->

<dependency>

<groupId>org.apache.jena</groupId>

<artifactId>jena-fuseki</artifactId>

<version>0.2.7</version>

<scope>test</scope>

</dependency>

<dependency>

<groupId>org.apache.jena</groupId>

<artifactId>jena-fuseki</artifactId>

<version>0.2.7</version>

<classifier>tests</classifier>

<scope>test</scope>

</dependency>

</dependencies>


<build>

<plugins>

<plugin>

<groupId>org.apache.maven.plugins</groupId>

<artifactId>maven-shade-plugin</artifactId>

<version>2.1</version>

<configuration>

<!-- If the following is uncommented out then this project builds fine -->

<!-- <createDependencyReducedPom>false</createDependencyReducedPom> -->

</configuration>

<executions>

<execution>

<phase>package</phase>

<goals>

<goal>shade</goal>

</goals>

</execution>

</executions>

</plugin>

</plugins>

</build>

</project>


Essentially the issue appears to be down to the fact that the POM references 
both the JAR and tests JAR artifacts of a module (jena-fuseki in this case) 
while also referencing another module (jena-arq) which is a transitive 
dependency of the other modules.  Per the XML comments if I only pull in one of 
the JARs for jena-fuseki things will work fine, but if I pull in both 
dependencies then shade will hang repeatedly creating the dependency reduced 
POM.  Equally if you don't have a dependency between pulled in that is a 
dependency of the other dependencies (jena-arq in my example) then again things 
will work fine.


However with this minimal example run at the console I see the following:


[INFO] Replacing original artifact with shaded artifact.

[INFO] Replacing 
/Users/rvesse/Documents/workspace/shade-dpr-bug/target/shade-dpr-bug-0.0.1-SNAPSHOT.jar
 with 
/Users/rvesse/Documents/workspace/shade-dpr-bug/target/shade-dpr-bug-0.0.1-SNAPSHOT-shaded.jar

[INFO] Dependency-reduced POM written at: 
/Users/rvesse/Documents/workspace/shade-dpr-bug/dependency-reduced-pom.xml

[INFO] Dependency-reduced POM written at: 
/Users/rvesse/Documents/workspace/shade-dpr-bug/dependency-reduced-pom.xml

[INFO] Dependency-reduced POM written at: 
/Users/rvesse/Documents/workspace/shade-dpr-bug/dependency-reduced-pom.xml

[INFO] Dependency-reduced POM written at: 
/Users/rvesse/Documents/workspace/shade-dpr-bug/dependency-reduced-pom.xml

[INFO] Dependency-reduced POM written at: 
/Users/rvesse/Documents/workspace/shade-dpr-bug/dependency-reduced-pom.xml

[INFO] Dependency-reduced POM written at: 
/Users/rvesse/Documents/workspace/shade-dpr-bug/dependency-reduced-pom.xml

[INFO] Dependency-reduced POM written at: 
/Users/rvesse/Documents/workspace/shade-dpr-bug/dependency-reduced-pom.xml

[INFO] Dependency-reduced POM written at: 
/Users/rvesse/Documents/workspace/shade-dpr-bug/dependency-reduced-pom.xml

[INFO] Dependency-reduced POM written at: 
/Users/rvesse/Documents/workspace/shade-dpr-bug/dependency-reduced-pom.xml

[INFO] Dependency-reduced POM written at: 
/Users/rvesse/Documents/workspace/shade-dpr-bug/dependency-reduced-pom.xml

[INFO] Dependency-reduced POM written at: 
/Users/rvesse/Documents/workspace/shade-dpr-bug/dependency-reduced-pom.xml

[INFO] Dependency-reduced POM written at: 
/Users/rvesse/Documents/workspace/shade-dpr-bug/dependency-reduced-pom.xml


This will continue indefinitely until you kill the process.  If I watch the 
dependency-reduced-pom.xml on the file system the plugin appears to be 
continually deleting and rewriting this file, each time the file is written it 
is larger than the previous write.  This implies to me that somehow the DPR 
creation is getting stuck and not managing to reach a suitable halting state.  
On the occasions when I have managed to kill the process while the DPR is 
non-empty it appears that the problem is that the plugin is adding <exclusions> 
to the non-test jar version of the dependency and is just repeatedly adding the 
same set of exclusions.


I'm not familiar with the Maven code base and unfortunately I don't have any 
free time to go delving into the code myself so if someone who knows the plugin 
could investigate this it would be much appreciated.  As I said I have a 
workaround (even if is less than ideal) so a resolution is by no means urgent 
but this certainly seems like a bug that needs addressing.  As a naïve (and 
clearly non-maven expert) suggestion since test dependencies aren't transitive 
anyway would a simple fix be to simple have DPR creation remove any 
<scope>test</scope> dependencies as a first step?


Thanks,


Rob

Reply via email to