Maven assembly: generate a resource zip file and include it into the main assembly zip file -
how can proceed include generated zip file main zip file maven assembly plugin?
for example, have following folder structure:
./foldera/ ./file1
and want generate zip file content this:
foldera.zip file1
here simplified config':
pom.xml
<?xml version="1.0" encoding="utf-8"?> <project > <build> <plugins> <plugin> <groupid>org.apache.maven.plugins</groupid> <artifactid>maven-assembly-plugin</artifactid> <configuration> <appendassemblyid>false</appendassemblyid> <descriptor>${basedir}/assembly-zipfoldera.xml</descriptor> <finalname>foldera.zip</finalname> </configuration> </plugin> <plugin> <groupid>org.apache.maven.plugins</groupid> <artifactid>maven-assembly-plugin</artifactid> <configuration> <appendassemblyid>false</appendassemblyid> <descriptor>${basedir}/assembly.xml</descriptor> <finalname>${module-zipfinalname}</finalname> </configuration> </plugin> </plugins> </build> </project>
assembly-zipfoldera.xml
<assembly> <id>foldera-zip</id> <includebasedirectory>false</includebasedirectory> <formats> <format>zip</format> </formats> <filesets> <fileset> <directory>foldera</directory> <outputdirectory>/</outputdirectory> </fileset> </filesets> </assembly>
assembly.xml
<assembly> <id>main</id> <includebasedirectory>false</includebasedirectory> <formats> <format>zip</format> </formats> <files> <file> <source>file1</source> </file> <file> <source>foldera.zip</source> </file> </files> </assembly>
===> config, maven complains can't find foldera.zip...
don't declare plugin twice; instead, need declare 2 executions of maven-assembly-plugin
.
the first execution create first assembly , then, second execution use assembly create final one. both of executions bound package
phase, , maven invoke plugin's execution in order of declaration in pom.
<plugin> <artifactid>maven-assembly-plugin</artifactid> <version>2.6</version> <executions> <execution> <id>make-foldera</id> <goals> <goal>single</goal> </goals> <phase>package</phase> <configuration> <appendassemblyid>false</appendassemblyid> <descriptors> <descriptor>${basedir}/assembly-zipfoldera.xml</descriptor> </descriptors> <finalname>foldera</finalname> <!-- name without extension --> <attach>false</attach> </configuration> </execution> <execution> <id>make-assembly</id> <goals> <goal>single</goal> </goals> <phase>package</phase> <configuration> <appendassemblyid>false</appendassemblyid> <descriptors> <descriptor>${basedir}/assembly.xml</descriptor> </descriptors> <finalname>${module-zipfinalname}</finalname> </configuration> </execution> </executions> </plugin>
a couple of notes:
- the
<finalname>
should not contain extension,finalname
offoldera
produce archivefoldera.zip
after zip assembly made. the first assembly created inside build directory,
target
default. such, second 1 needs reference there with:<file> <source>${project.build.directory}/foldera.zip</source> </file>
in assembly descriptor.
since first assembly not final one, don't want attached, i.e. additional artifact produced project. can disable setting
attach
false
. make sure last final 1 considered when deploying or releasing.descriptor
deprecated parameter, should usedescriptors
instead.
with such configuration, running mvn clean package
produce correct archive inside build folder.
Comments
Post a Comment