One of my projects has a structure like this:
.\ca\<modulename>\dist\<modulename>.zip
I want to make a package that just has the zip files in a single package, so if I have submodules mod1
, mod2
, modn
, I'll end up with:
ZIP CONTENT:
mod1.zip
mod2.zip
...
modn.zip
What I've done so far is create a maven project and, using maven dependency
and assembly
plugins I got to this:
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>unpack</id>
<phase>generate-sources</phase>
<goals>
<goal>unpack</goal>
</goals>
<configuration>
<artifactItems>
<artifactItem>
<groupId>es.xunta.emprego.cntxes</groupId>
<artifactId>myproject-cas</artifactId>
<version>${cas.version}</version>
<overWrite>true</overWrite>
<outputDirectory>target/dependency</outputDirectory>
<type>zip</type>
<includes>ca/**/dist/*.zip</includes>
</artifactItem>
</artifactItems>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<descriptor>src/main/assembly/zip.xml</descriptor>
<appendAssemblyId>false</appendAssemblyId>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<!-- this is used for inheritance merges -->
<phase>package</phase>
<!-- append to the packaging phase. -->
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
With this being assembly/zip.xml
:
<?xml version="1.0" encoding="UTF-8" ?>
<assembly>
<id>bin</id>
<formats>
<!-- formato de salida del empaquetado -->
<format>zip</format>
</formats>
<includeBaseDirectory>false</includeBaseDirectory>
<fileSets>
<fileSet>
<outputDirectory>/</outputDirectory>
<directory>target/dependency</directory>
<includes>
<include>/**/dist/*.zip</include>
</includes>
<useDefaultExcludes>true</useDefaultExcludes>
</fileSet>
</fileSets>
</assembly>
But this is respecting my original zip's folder structure, so the result is:
ZIP CONTENT
ca\mod1\dist\mod1.zip
ca\mod2\dist\mod2.zip
...
ca\modn\dist\modn.zip
It might seem a small issue but the number of modules is big and gathering the different zip files is very annoying having to browse through every folder. I've been struggling with assembly
and dependency
but haven't found a way to achieve what I want. Note that I'm using wildcards (ca/**/dist/*.zip
) because I don't know prior to compilation the name of the files that will be there.
Any help please?
Are
mod1.zip
,mod2.zip
, etc. installed, or can they be installed into your local repository? You could use themaven-dependency-plugin
:This gets you back to maintaining this dependency list given a dynamic module list, but if you can figure out how to make the dependency list dynamic, then this might get you farther.
You need a plugin between the dependency:unpack and the assembly:single task that flattens your resources.
You could fiddle with the resources:copy-resources task, but that probably won't do the trick, as confirmed here: Maven : copy files without subdirectory structure
For such cases, the maven ant plugin was created, as describe in @Fabien's answer, to invoke all sorts of non-standard behaviours.
I don't know if there's a way to do this but this question might help you find a way through : execute ant / groovy script inside maven
According to the linked answer, here is an ANT example (I can't try it right now) with the maven ANT plugin :
At least, the version 3.0.3 of Maven is required in order to insure plugins execution order on same phase.