Prakash
Prakash

Reputation: 165

maven assembly packge understanding

Need help in understanding the blow maven assembly file. We have lot of maven projects, this copies all the dependencies to the xc/plugins folder. But I added a dependency it was not getting packaged. later i found that i have to add it under dependency not under dependencySet. Even that i need to add it under then parent pom only then it gets added. If add it under child pom files, it is not getting packaged. Need help in under standing this.

How it picks all the dependency jars.

<moduleSets>
    <moduleSet>
      <binaries>
        <outputDirectory>xc/plugins</outputDirectory>
        <outputFileNameMapping>
          ${module.groupId}.${module.artifactId}-${module.version}${dashClassifier?}.${module.extension}
        </outputFileNameMapping>
        <unpack>false</unpack>
        <includeDependencies>false</includeDependencies>
      </binaries>
      <excludes>
        <exclude>org.opendaylight.controller:sal.networkconfiguration</exclude>
        <exclude>org.opendaylight.controller:sal.networkconfiguration.implementation</exclude>
      </excludes>
    </moduleSet>
  </moduleSets>
  <dependencySets>
    <dependencySet>
      <outputDirectory>xc/plugins</outputDirectory>
      <excludes>
        <exclude>org.slf4j:slf4j-api</exclude>
        <exclude>ch.qos.logback:logback-core</exclude>
        <exclude>ch.qos.logback:logback-classic</exclude>
        <exclude>com.sun.jersey:jersey-core</exclude>
        <exclude>com.sun.jersey:jersey-json</exclude>
      </excludes>
      <outputFileNameMapping>
        ${artifact.groupId}.${artifact.artifactId}-${artifact.baseVersion}${dashClassifier?}.${artifact.extension}
      </outputFileNameMapping>
      <unpack>false</unpack>
      <scope>runtime</scope>
      <useTransitiveDependencies>false</useTransitiveDependencies>
      <useProjectArtifact>false</useProjectArtifact>
    </dependencySet>
  </dependencySets>

Upvotes: 1

Views: 262

Answers (1)

Daniel
Daniel

Reputation: 4211

The assembly-plugin is usually the last thing a Maven power user learns to master. It has its quirks, but (as always) once you understand what it actually does and more importantly how it works, you'll find it easier to work with.

Let's say you have a multi-module build like so:

pom.xml (root pom that lists the modules mod1, mod2, mod3 and assembly)
|
+-- mod1
|   |
|   +-- pom.xml
|
+-- mod2
|   |
|   +-- pom.xml
|
+-- mod3
|   |
|   +-- pom.xml
|
+-- assembly
    |
    +-- pom.xml
    +-- assembly-file.xml (the assembly descriptor)

Anything listed in <moduleSets> applies to mod1, mod2, mod3 and assembly. You have specified <includeDependencies>false</includeDependencies> under <binaries>, so this configuration won't include any dependencies, only the artifacts produced by mod1, mod2, mod3 and assembly.

Most of the time, I tend to specify <packaging>pom</packaging> for the assembly module. The reason for this is that the assembly doesn't usually contain any code, it's just an assembly, so I am not interested in including anything from it.

In the other corner, <dependencySets> (not the one under <binaries>) applies to the dependencies of the assembly POM only, nothing else. So unless you specify mod1, mod2 and mod3 as dependencies to the assembly POM (which is totally fine, if it's what you want), this <dependencySets> won't do much; otherwise, it works as expected.

The <binaries> section contains its own <dependencySets> if you want to configure the dependency-set of the entire multi-module build. But in your particular case, you have declared <includeDependencies>false</includeDependencies> so declaring a <dependencySets> under <binaries> becomes contradictive.

Lastly, <fileSets> and <files> applies to the assembly POM, so unless there are any files in that project (e.g. under src/main/resources), you won't be using it. If you need to do some specific inclusion of files from mod1, mod2 or mod3, use <unpackOptions>, either under <binaries> or <dependencySets> depending on what you want to do.

Upvotes: 1

Related Questions