Search code examples
mavenbuildmaven-pluginmaven-assembly-plugin

Maven assembly Include too many dependencies in a ZIP


I have a Maven multi-module project. In one module, we create a ZIP with maven-assembly-plugin plugin. The configuration for this:

<baseDirectory>/</baseDirectory>
  <formats>
    <format>zip</format>
  </formats>
  <includeBaseDirectory>false</includeBaseDirectory>
  <dependencySets>
    <dependencySet>
        <outputDirectory>/</outputDirectory>    
        <useProjectArtifact>true</useProjectArtifact>           
        <excludes>
            <exclude>
                com.sample.blabla:test-core-client
            </exclude>
        </excludes>
        <scope>runtime</scope>
    </dependencySet>
  </dependencySets>

And the pom config for this:

<execution>
    <id>make-service-client-with-dependencies-zip</id>
    <phase>package</phase>
    <goals>
        <goal>single</goal>
    </goals>
    <configuration>
        <finalName>${service-client-with-dependencies.zip.filename}</finalName>
            <appendAssemblyId>true</appendAssemblyId>
        <outputDirectory>${project.build.directory}/zip</outputDirectory>
        <descriptors>
            <descriptor>src/main/assembly/test-service-client-with-dependencies.xml</descriptor>
        </descriptors>
    </configuration>
</execution>

Unfortunately the created ZIP contains much more jar-s, that we would like... for example: 37 X maven-XXX JAR, a lot of spring jars, wagon jars,...etc.

But we wouldn't like to include these jars, just which necessary for runtime. How can we do it?


Solution

  • Maven assembly plugin includes only the jars which are in runtime scope as per your configuration. You can run mvn dependency:tree and compare the output with the contents of your zip.

    You can try setting the property useTransitiveDependencies to false. This will exclude all transitive dependencies from the zip. But this can have unpleasant side-effects.