Maven 2.x Assembly Plugin

Fat JAR assemblies may result in JARs with duplicate files

Details

  • Type: Bug Bug
  • Status: Closed Closed
  • Priority: Major Major
  • Resolution: Duplicate
  • Affects Version/s: None
  • Fix Version/s: 2.2-beta-3
  • Component/s: None
  • Labels:
    None
  • Environment:
    Maven 2.0.8
  • Number of attachments :
    0

Description

When building a fat JAR assembly (format=jar, dependencySet.unpack=true), if some of the dependencies contain files with the same path and name as files in any other dependencies and/or the current project, the generated JAR file contains duplicate files.

The root issue is that ZIP files allow duplicate files, and JAR files are just special ZIP files. However, when a JAR file contains duplicate files, the results are unpredictable – there's no way to know which file "wins."

Internally, (as far as I can tell) Maven's DefaultAssemblyArchiver [2] uses an ArchiverManager to get an Archiver based on the format name ("jar"). This Archiver is probably a MavenArchiver [3], which delegates to a JarArchiver [4], which is a subclass of ZipArchiver [5] and AbstractZipArchiver [6]. AbstractZipArchiver has a protected instance variable of type String named "duplicate", the values of which can be one of "preserve", "fail" and "add". The default is "add".

I'm not sure if this needs to be fixed at the JarArchiver level (initialize the "duplicate" instance var to "preserve"), or at the DefaultAssemblyArchiver level (as was done with WAR assemblies for MNG-1274 – see the createWarArchiver() method), or somewhere else.

As an example of how other projects handle this, Ant's Jar task documentation page [1] includes a bolded warning which describes the issue and provides the "duplicate" attribute, which can be set to "add", "preserve" or "fail".

[1] http://ant.apache.org/manual/CoreTasks/jar.html
[2] http://svn.apache.org/repos/asf/maven/plugins/trunk/maven-assembly-plugin/src/main/java/org/apache/maven/plugin/assembly/archive/DefaultAssemblyArchiver.java
[3] http://maven.apache.org/shared/maven-archiver/xref/index.html
[4] http://fisheye.codehaus.org/browse/~raw,r=4612/plexus/plexus-components/trunk/plexus-archiver/src/main/java/org/codehaus/plexus/archiver/jar/JarArchiver.java
[5] http://fisheye.codehaus.org/browse/~raw,r=4573/plexus/plexus-components/trunk/plexus-archiver/src/main/java/org/codehaus/plexus/archiver/zip/ZipArchiver.java
[6] http://fisheye.codehaus.org/browse/~raw,r=4573/plexus/plexus-components/trunk/plexus-archiver/src/main/java/org/codehaus/plexus/archiver/zip/AbstractZipArchiver.java

Issue Links

Activity

Hide
Antony Stubbs added a comment -

Appears to be related.

Show
Antony Stubbs added a comment - Appears to be related.
Hide
John Casey added a comment -

See MASSEMBLY-285. The latest code supports the following plugin configuration:

<archiverConfig>
  <duplicateBehavior>skip</duplicateBehavior>
</archiverConfig>

The default setting is 'add' which allows duplicates.

Show
John Casey added a comment - See MASSEMBLY-285. The latest code supports the following plugin configuration:
<archiverConfig>
  <duplicateBehavior>skip</duplicateBehavior>
</archiverConfig>
The default setting is 'add' which allows duplicates.

People

Vote (2)
Watch (3)

Dates

  • Created:
    Updated:
    Resolved: