The maven assembly plugin is not using the finalName for installing with attach=true?

Roland Wiesemann picture Roland Wiesemann · May 2, 2010 · Viewed 19.4k times · Source

I have configured following assembly:

<build>
    <plugins>
        <plugin>
            <artifactId>maven-assembly-plugin</artifactId>
            <version>2.2-beta-5</version>
            <executions>
                <execution>
                    <id>${project.name}-test-assembly</id>
                    <phase>package</phase>
                    <goals>
                        <goal>single</goal>
                    </goals>
                    <configuration>
                        <appendAssemblyId>false</appendAssemblyId>
                        <finalName>${project.name}-test</finalName>
                        <filters>
                            <filter>src/assemble/test/distribution.properties</filter>
                        </filters>
                        <descriptors>
                            <descriptor>src/assemble/distribution.xml</descriptor>
                        </descriptors>
                        <attach>true</attach>
                    </configuration>
                </execution>
                <execution>
                    <id>${project.name}-prod-assembly</id>
                    <phase>package</phase>
                    <goals>
                        <goal>single</goal>
                    </goals>
                    <configuration>
                        <appendAssemblyId>false</appendAssemblyId>
                        <finalName>${project.name}-prod</finalName>
                        <filters>
                            <filter>src/assemble/prod/distribution.properties</filter>
                        </filters>
                        <descriptors>
                            <descriptor>src/assemble/distribution.xml</descriptor>
                        </descriptors>
                        <attach>true</attach>
                    </configuration>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>

This produced two zip-files:

  • distribution-prod.zip
  • distribution-test.zip

My expectation for the property attach=true is, that the two zip-files are installed with the name as given in property finalName. But the result is, only one file is installed (attached) to the artifact. The maven protocol is:

  • distrib-0.1-SNAPSHOT.zip
  • distrib-0.1-SNAPSHOT.zip

The plugin is using the artifact-id instead of property finalName! Is this a bug?

The last installation is overwriting the first one. What can i do to install this two files with different names?

Thanks for your investigation. Roland

Answer

Pascal Thivent picture Pascal Thivent · May 2, 2010

The last installation is overwriting the first one. What can i do to install this two files with different names?

As expected (I don't know if this is a bug or not but that's how the assembly plugin works). To avoid this, you will have to set the appendAssemblyId properties to true and, to obtain an equivalent result, to change the finalName to ${project.name} and the assemby id to test and prod (i.e. to use two assembly descriptors). Something like this:

<build>
  <plugins>
    <plugin>
      <artifactId>maven-assembly-plugin</artifactId>
      <version>2.2-beta-5</version>
      <executions>
        <execution>
          <id>${project.name}-test-assembly</id>
          <phase>package</phase>
          <goals>
            <goal>single</goal>
          </goals>
          <configuration>
            <appendAssemblyId>true</appendAssemblyId>
            <finalName>${project.name}</finalName>
            <filters>
                <filter>src/assemble/test/distribution.properties</filter>
            </filters>
            <descriptors>
              <descriptor>src/assemble/distribution-test.xml</descriptor>
            </descriptors>
          </configuration>
        </execution>
        <execution>
          <id>${project.name}-prod-assembly</id>
          <phase>package</phase>
          <goals>
            <goal>single</goal>
          </goals>
          <configuration>
            <appendAssemblyId>true</appendAssemblyId>
            <finalName>${project.name}</finalName>
            <filters>
              <filter>src/assemble/prod/distribution.properties</filter>
            </filters>
            <descriptors>
              <descriptor>src/assemble/distribution-prod.xml</descriptor>
            </descriptors>
          </configuration>
        </execution>
      </executions>
    </plugin>
  </plugins>
</build>

Where distribution-test.xml and distribution-prod.xml declare assembly id test and prod respectively.