I have a similar situation to Add jar-with-dependencies artifact from other Maven module, however the suggested solution did not work for me. I've tried using both moduleSets
and dependencySets
. So here we go:
I have a multi-module maven project:
parent
|
+-myProject
|
+-myProjectTests
I want myProjectTests to have the jar-with-dependencies
produced by myProject in its output directory, to run integration tests etc on (I'm using a framework that requires an actual jar to run)
parent pom.xml:
<project>
<groupId>myGroup</groupId>
<artifactId>parent</artifactId>
<packaging>pom</packaging>
<modules>
<module>myProject</module>
<module>myProjectTests</module>
</modules>
</project>
myProject pom.xml:
<project>
<groupId>myGroup</groupId>
<artifactId>myProject</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<build>
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
</plugin>
</plugins>
</build>
</plugins>
</project>
myProjectTests pom.xml:
<project>
<groupId>myGroup</groupId>
<artifactId>myProjectTests</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>pom</packaging>
<dependencies>
<dependency>
<groupId>myGroup</groupId>
<artifactId>myProject</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.4</version>
<executions>
<execution>
<id>prepareTests</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
<configuration>
<descriptors>
<descriptor>prepare.xml</descriptor>
</descriptors>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
prepare.xml:
<assembly>
<id>prepareTests</id>
<formats>
<format>dir</format>
</formats>
<includeBaseDirectory>false</includeBaseDirectory>
?????
</assembly>
If I try specifying moduleSets
for the ????? in my prepare.xml like so:
<moduleSets>
<moduleSet>
<useAllReactorProjects>true</useAllReactorProjects>
<includes>
<include>myGroup:myProject</include>
</includes>
<binaries>
<attachmentClassifier>jar-with-dependencies</attachmentClassifier>
<unpack>false</unpack>
</binaries>
</moduleSet>
</moduleSets>
I get this output:
[WARNING] The following patterns were never triggered in this artifact inclusion filter: o 'myGroup.myProject' [WARNING] The following patterns were never triggered in this artifact inclusion filter: o 'myGroup.myProject' [WARNING] NOTE: Currently, inclusion of module dependencies may produce unpredictable results if a version conflict occurs. [ERROR] Failed to execute goal org.apache.maven.plugins:maven-assembly-plugin:2.4:single (prepareTests) on project myProjectTests: Failed to create assembly: Error creating assembly archive prepareTests: You must set at least one file. -> [Help 1]
I have scoured the maven documentation and the internets for solutions, and have tried many different combinations of the various flags, all with the same error.
If I specify dependencySets
in the ????? like so:
<dependencySets>
<dependencySet>
<includes>
<include>myGroup:myProject:jar-with-dependencies:0.0.1-SNAPSHOT</include>
</includes>
<unpack>false</unpack>
</dependencySet>
</dependencySets>
I get this:
[WARNING] Cannot include project artifact: myGroup:myProjectTests:pom:0.0.1-SNAPSHOT; it doesn't have an associated file or directory. [WARNING] The following patterns were never triggered in this artifact inclusion filter: o 'myGroup:myProject:jar-with-dependencies:0.0.1-SNAPSHOT' [ERROR] Failed to execute goal org.apache.maven.plugins:maven-assembly-plugin:2.4:single (prepareTests) on project myProjectTests: Failed to create assembly: Error creating assembly archive prepareTests: You must set at least one file. -> [Help 1]
Again, I have tried lots of different combinations of flags, and removed the jar-with-dependencies
classifier, all to no effect.
There is nothing in the debug logs in both cases that is helpful, and I have explored some avenues suggested by the debug logs.
What I want is simple - to have the jar-with-dependencies file produced by myProject to be put into the output directory of myProjectTests during the package phase, ideally without using direct file paths. How do I get maven to do that?
Turns out this is a known maven bug - the assembly plugin doesn't work correctly when the submodules don't have the aggregator project as its parent - MASSEMBLY-600. Looks like I'll have to use direct file dependencies instead.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With