Maven assembly plugin cannot put two filesets into the same folder

39 views Asked by At

I have a maven-assembly-plugin file defined as:

<assembly
    xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2 http://maven.apache.org/xsd/assembly-1.1.2.xsd">
    <id>zip-assembly</id>
    <formats>
        <format>zip</format>
    </formats>
    <fileSets>
        <fileSet>
            <directory>${project.basedir}/my-service/target</directory>
            <outputDirectory>app</outputDirectory>
            <fileMode>0755</fileMode>
            <includes>
                <include>*.jar</include>
            </includes>
        </fileSet>
        <fileSet>
            <directory>${project.basedir}/my-library/target</directory>
            <outputDirectory>app</outputDirectory>
            <fileMode>0755</fileMode>
            <includes>
                <include>*.jar</include>
            </includes>
        </fileSet>
    </fileSets>
</assembly>

Both filesets write to the same directory "app". However, what I found is that only the files in the second fileset are written to the app directory. Probably the second one overwrites the first fileset.

Can someone tell me how I can write two filesets into the same folder?

1

There are 1 answers

0
Andrés S. Sanguino On

I tried to replicate your assembly, and there are just overwritten files in case of having the same name. If not, they have been added right (both file set). In my execution, the ones that remain are from the first file set.

Is it your case ? Maybe you could rename them after compiling, and using something like an ant-run before executing the package phase:

<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-antrun-plugin</artifactId>
  <version>3.1.0</version>
  <executions>
    <execution>
      <phase>prepare-package</phase>
      <configuration>
        <target>
          <rename src="${project.basedir}/my-service/target/*.jar" dest="${project.basedir}/my-service/target/target-*.jar"/>
        </target>
      </configuration>
      <goals>
        <goal>run</goal>
      </goals>
    </execution>
  </executions>
</plugin>