I'm having a spot of bother with the Maven assembly goal. I have a project which has a number of dependencies each of which may have their own transitive dependencies. If I run mvn dependency:tree than I can see all the dependencies including transitive are satisfied.
This is not the case when I run the assembly goal.What I would like is when I add an dependency to be included, then all of its transitive dependencies are also included. In the following example I have three dependencies I would like to be included. So when the assembly is made I expected to have those dependencies and any transitive dependencies for those dependencies as well.
<assembly>
<baseDirectory>${artifactId}/${artifactId}-${version}</baseDirectory>
<formats>
<format>zip</format>
</formats>
<fileSets>
</fileSets>
<dependencySets>
<dependencySet>
<unpack>false</unpack>
<scope>runtime</scope>
<outputDirectory>/lib
</outputDirectory>
<includes>
<include>com.acme.core:library-1</include>
<include>com.acme.core:library-2</include>
<include>com.acme.core:library-2</include>
</includes>
</dependencySet>
</dependencySets>
But if you open the the zip file you'll only find those three dependencies present which means at runtime the application is not fit for purpose due to missing libraries. I find this totally unintuitive as it goes against the behaviour one would expect from the POM.
Has anyone encountered this problem and is there a solution?
Transitive Dependencies. Maven avoids the need to discover and specify the libraries that your own dependencies require by including transitive dependencies automatically. This feature is facilitated by reading the project files of your dependencies from the remote repositories specified.
Multiple transitive dependencies can be excluded by using the <exclusion> tag for each of the dependency you want to exclude and placing all these exclusion tags inside the <exclusions> tag in pom. xml. You will need to mention the group id and artifact id of the dependency you wish to exclude in the exclusion tag.
The "includes" and "excludes" apply to the transitive dependencies as well. Try adding the following configuration to your dependencySet
:
<useTransitiveFiltering>true</useTransitiveFiltering>
http://maven.apache.org/plugins/maven-assembly-plugin/assembly.html#dependencySet
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