At one of my customers, when we create a new release of our application (consisting of several WAR files) we have to supply one zip-file with all the WAR files in it. Also a zip file containing the compiled Jasper reports must be added to it. Although this can be done by hand, it is of course much nicer to make part of the automated build cycle of our Maven build!
Now luckily there is a standard plugin available which can do this for us. The plugin is called ‘maven-assembly-plugin’ and it takes an ‘assembly.xml’ file to be configured. To configure the plugin in your project to package all compiled reports you will get something like:
<plugin> <artifactId>maven-assembly-plugin</artifactId> <configuration> <descriptors> <descriptor>src/main/jasperreports/assemble.xml</descriptor> </descriptors> </configuration> </plugin>
As you can see I have added the ‘assemble.xml’ file to the directory ‘src/main/jasperreports/’. In this ‘assemble.xml’ file I have put the following:
<id>reports</id> <formats> <format>zip</format> </formats> <includeBaseDirectory>false</includeBaseDirectory> <fileSets> <fileSet> <directory>src/main/jasperreports/compiled</directory> <includes> <include>*.jasper</include> </includes> <outputDirectory>/</outputDirectory> </fileSet> </fileSets> </assembly>
This configuration is based on the module described in this post about compiling Jasper reports with Maven2. This will create the zip file containing all compiled reports in this project.
Since there are some problems with the plugin and multi-module Maven project (like described here) I also added a new module to my project to create the overall zip file: my-app-distribution.
In the pom file of this module I added:
... <build> <plugins> <plugin> <artifactId>maven-assembly-plugin</artifactId> <configuration> <descriptors> <descriptor>src/main/resources/assemble.xml</descriptor> </descriptors> </configuration> </plugin> </plugins> </build> <dependencies> <dependency> <groupId>net.pascalalma</groupId> <artifactId>my-app-1</artifactId> <version>1.0.0</version> <type>war</type> </dependency> <dependency> <groupId>net.pascalalma</groupId> <artifactId>my-app-2</artifactId> <version>1.0.0</version> <type>war</type> </dependency> </dependencies> ...
And in the ‘assemble.xml’ I put:
<assembly> <id>kit</id> <formats> <format>zip</format> </formats> <includeBaseDirectory>false</includeBaseDirectory> <dependencySets> <dependencySet> <excludes> <exclude>net.pascalalma:my-app-distribution</exclude> </excludes> </dependencySet> </dependencySets> <files> <file> <source>..\my-app-1\target\my-app-1-reports.zip</source> </file> </files> </assembly>
This assembly will zip all dependencies (except the .jar of its own module) and the reports.zip we have created before. Of course you can do much, much more with this plugin. You can read about that here including more examples.