Maven – Multiple files with maven-assembly-plugin –> “already added, skipping”

mavenmaven-assembly-plugin

I need to create multiple tar files in a tar-by-environment package.

Every different environment has a folder with an only file "environment.properties", so I've got to merge the project content with the environment.properties file for each of my environments: RC, BC, PROD.

I'm using maven-assembly-plugin to do this, so there are 3 assembly descriptors similar to this assembly with different "id":

<assembly
    xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0 http://maven.apache.org/xsd/assembly-1.1.0.xsd">
    <id>pack-content-rc</id>
    <includeBaseDirectory>false</includeBaseDirectory>
    <formats>
        <format>tar</format>
    </formats>
    <fileSets>
        <fileSet>
            <outputDirectory>/definitions</outputDirectory>
            <directory>definitions</directory>
            <includes>
                <include>*.*</include>
            </includes>
            <excludes>
                <exclude>.*</exclude>
            </excludes>
        </fileSet>
        <fileSet>
            <outputDirectory>/library</outputDirectory>
            <directory>library</directory>
            <includes>
                <include>*.*</include>
            </includes>
            <excludes>
                <exclude>.*</exclude>
            </excludes>
        </fileSet>
        <fileSet>
            <outputDirectory>/messages</outputDirectory>
            <directory>messages</directory>
            <includes>
                <include>*.*</include>
            </includes>
            <excludes>
                <exclude>.*</exclude>
            </excludes>
        </fileSet>
        <fileSet>
            <outputDirectory>/templates</outputDirectory>
            <directory>templates</directory>
            <includes>
                <include>**/*</include>
            </includes>
            <excludes>
                <exclude>.*</exclude>
            </excludes>
        </fileSet>
        <fileSet>
            <outputDirectory>/variables</outputDirectory>
            <directory>variables</directory>
            <includes>
                <include>*.*</include>
            </includes>
            <excludes>
                <exclude>.*</exclude>
            </excludes>
        </fileSet>
        <fileSet>
            <outputDirectory>/variables</outputDirectory>
            <directory>target/escape/rc</directory>
            <includes>
                <include>*.*</include>
            </includes>
        </fileSet>      
    </fileSets>
</assembly>

And the maven configuration of the plugin is:

...
<artifactId>maven-assembly-plugin</artifactId>
<version>2.2.2</version>
<executions>
    <execution>
        <id>make-assembly</id>
        <phase>package</phase>
        <goals>
            <goal>single</goal>
        </goals>
        <configuration>
            <descriptors>
                <descriptor>pack-content-rc.xml</descriptor>
                <descriptor>pack-content-bc.xml</descriptor>
                <descriptor>pack-content-prod.xml</descriptor>
            </descriptors>
        </configuration>
    </execution>
</executions>
...

And the output log is:

[INFO] --- maven-assembly-plugin:2.2.2:single (make-assembly) @ nibbler-content ---
[INFO] Reading assembly descriptor: pack-content-rc.xml
[INFO] Reading assembly descriptor: pack-content-bc.xml
[INFO] Reading assembly descriptor: pack-content-prod.xml
[INFO] nibbler-content-19.0.1-SNAPSHOT-rc/variables/environment.properties already added, skipping
[INFO] Building tar : /Users/ger/Documents/Work/nibbler-content/target/nibbler-content-19.0.1-SNAPSHOT-pack-content-rc.tar
[INFO] nibbler-content-19.0.1-SNAPSHOT-rc/variables/environment.properties already added, skipping
[INFO] nibbler-content-19.0.1-SNAPSHOT-bc/variables/environment.properties already added, skipping
[INFO] Building tar : /Users/ger/Documents/Work/nibbler-content/target/nibbler-content-19.0.1-SNAPSHOT-pack-content-bc.tar
[INFO] nibbler-content-19.0.1-SNAPSHOT-bc/variables/environment.properties already added, skipping
[INFO] nibbler-content-19.0.1-SNAPSHOT-prod/variables/environment.properties already added, skipping
[INFO] Building tar : /Users/ger/Documents/Work/nibbler-content/target/nibbler-content-19.0.1-SNAPSHOT-pack-content-prod.tar
[INFO] nibbler-content-19.0.1-SNAPSHOT-prod/variables/environment.properties already added, skipping
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------

The problem is that the 3 resulting files have the same environment.properties file, the first file to be exact, so I end up having 3 files that are exactly the same package.

I assume that the assembly process uses a directory to compose the tar, so it copies the first file, and for the second descriptor the file is already there…

Is there a way to avoid this to happend? Something like a clean before running each descriptor?
Should I use maven-ant-run plugin or something like that?

Thanks!

Best Answer

The already added, skipping thing came first with version 2.2 of the plugin, you may try v2.1.