I have a project which is using a maven assembly plugin to include a bunch of files into a tar. Now I want to include a few more files in that tar, but first I want to zip them up and actually include that zip file.
I tried doing something like this: maven-assembly plugin - how to create nested assemblies
So basically created 2 executions inside the maven assempbly plugin and have the first execution create the required zip file that the second execution can package into a tar.
But I get the error saying the zip file 'is not a file'.
What is wrong with what I am doing?
Is there a more efficient way to do this?
This is what I tried:
My POM:
<build>
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.3</version>
<executions>
<execution>
<id>create-zip</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
<configuration>
<descriptors>
<descriptor>zip.xml</descriptor>
</descriptors>
</configuration>
</execution>
<execution>
<id>create-tar</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
<configuration>
<descriptors>
<descriptor>tar.xml</descriptor>d
</descriptors>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
zip.xml
<assembly xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2"
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-id</id>
<formats>
<format>zip</format>
</formats>
<includeBaseDirectory>false</includeBaseDirectory>
<fileSets>
<fileSet>
<directory>${project.basedir}/src/main/resources/vertica_schema/schema_migrations</directory>
<outputDirectory>/</outputDirectory>
</fileSet>
</fileSets>
tar.xml
<assembly xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://maven.apache.org/plugins/maven-assembly- plugin/assembly/1.1.2"
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>tar-id</id>
<formats>
<format>tar.gz</format>
</formats>
<includeBaseDirectory>false</includeBaseDirectory>
<files>
<file>
<source>/*.zip</source>
<outputDirectory>/lib</outputDirectory>
<destName>schema_migrations.zip</destName>
</file>
</files>
The <source>
tag does not support *
: it is only possible to select a single file with it. Additionally, the zip file build by the first execution will be generated inside the target
folder by default, so you should point to that directory.
By default, the zip file will be named ${project.build.finalName}-zip-id.zip
. You can change this name by setting the finalName
attribute in the plugin configuration. Note that, by default, the assembly id will be concatenated to the finalName
. You can turn this off by switching the appendAssemblyId
flag to false
.
This is a working configuration:
<build>
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.3</version>
<executions>
<execution>
<id>create-zip</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
<configuration>
<descriptors>
<descriptor>zip.xml</descriptor>
</descriptors>
<finalName>myzip</finalName> <!-- Name of zip file -->
<appendAssemblyId>false</appendAssemblyId> <!-- Do not concatenate "zip-id" to the finalName" -->
</configuration>
</execution>
<execution>
<id>create-tar</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
<configuration>
<descriptors>
<descriptor>tar.xml</descriptor>d
</descriptors>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
with the following tar.xml
:
<assembly xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://maven.apache.org/plugins/maven-assembly- plugin/assembly/1.1.2"
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>tar-id</id>
<formats>
<format>tar.gz</format>
</formats>
<includeBaseDirectory>false</includeBaseDirectory>
<files>
<file>
<source>${project.basedir}/target/myzip.zip</source>
<outputDirectory>/lib</outputDirectory>
<destName>schema_migrations.zip</destName>
</file>
</files>
It is a good practice to keep everything that is generated by Maven under the target
directory. This is the working folder of Maven and you should not worry about keeping intermediate files in there.