Software Reuse Quick Tip #27

November 6, 2010

Use Maven Assemblies for Packaging Configuration Artifacts

The maven assembly plugin can be used to generate separate artifacts for environment-specific configuration files. This is very useful to separate binaries (jar, war, etc.) from configuration (xml, properties files, etc.). This enables deployment of a binary across any environment. Reusable components are often used in several applications and processes and they often have configuration information. Your clients will want to customize the configuration for testing/altering behavior and it is critical that your build process separates binaries from configuration.

Here’s the snippet for adding the plugin in the POM file:

<plugin>
            <artifactId>maven-assembly-plugin</artifactId>
            <version>2.2-beta-2</version>
            <configuration>
                <descriptors>
                    <descriptor>test-assembly.xml</descriptor>
                </descriptors>
            </configuration>
            <executions>
                <execution>
                    <id>zip</id>
                    <phase>package</phase>
                    <goals>
                        <goal>single</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>

Here’s an example packaging a zip:

<assembly>
<pre>  <id>some-assembly-identifier</id>
  <formats>
    <format>zip</format>
  </formats>
  <includeBaseDirectory>true</includeBaseDirectory>
  <fileSets>
    <fileSet>
      <outputDirectory><!--add folder--></outputDirectory>
      <directory>${basedir}/target/classes</directory>
      <includes>
         <include>*.xml</include>
      </includes>
    </fileSet>
  </fileSets>

</assembly>

Follow

Get every new post delivered to your Inbox.

%d bloggers like this: