Reputation: 161
I am working on a multi-module maven project with these modules
parent
|-- restful // this is a jersey restful service as a WAR
|-- shared // some stuff shared by all other modules as a jar
|-- cl-client // a commandline client to the restful service, needs assembly
The parent pom.xml uses dependencyManagement to list all dependencies used by all modules
The pom for cl-client includes the assembly plugin, configured to be executed at the package phase:
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.4</version>
<executions>
<execution>
<id>distro-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
<configuration>
<descriptors>
<descriptor>src/main/assembly/assembly.xml</descriptor>
</descriptors>
</configuration>
</execution>
</executions>
</plugin>
and the assembly.xml is as follows:
<assembly>
<id>commandlinable</id>
<formats>
<format>dir</format>
</formats>
<includeBaseDirectory>false</includeBaseDirectory>
<moduleSets>
<moduleSet>
<useAllReactorProjects>true</useAllReactorProjects>
<includes>
<include>my:cl-client</include>
</includes>
<binaries>
<outputDirectory>${artifactId}</outputDirectory>
<unpack>true</unpack>
<dependencySets>
<dependencySet>
<outputDirectory>${artifactId}/lib</outputDirectory>
<useProjectArtifact>true</useProjectArtifact>
<unpack>false</unpack>
<scope>runtime</scope>
</dependencySet>
</dependencySets>
</binaries>
</moduleSet>
</moduleSets>
</assembly>
When I run mvn package
, the cl-client modules assembles fine and does create the directory that I hoped for, but the only problem is that all dependencies jars are copied in the lib/ directory, even the ones that are only used by the "restful" module such as jersey related jars. I tried to flip the useProjectArtifact
flag, but it didn't seem to make any difference.
So I am just wondering if there is anyway I can tell Maven assembly to include only the jars required by the cl-client module. I poured through quite a few online resources on Maven assembly on multi-module projects, but wasn't able to get any clear answers.
Upvotes: 1
Views: 2876
Reputation: 69389
Use the mvn dependency:tree
command to understand which dependencies exist between your modules. You'll probably discover an artifact has a transitive dependency on jersey, which is why it's being included.
Upvotes: 1