Thursday 14 August 2014

Maven Assembly Plugin Usage


An "assembly" is a group of files, directories, and dependencies that are assembled into an archive format and distributed.
The Assembly Plugin provides a descriptor format which allows you to define an arbitrary assembly of files and directories from a project. 
The main goal in the assembly plugin is the single goal. It is used to create all assemblies. All goals except assembly:single have been deprecated.

Add Assembly plugin in pom.xml
    <build>
            <plugins>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-assembly-plugin</artifactId>
                    <version>2.4</version>
                    <configuration>
                        <descriptors>
                            <descriptor>src/main/assembly/descriptor.xml
                            </descriptor>
                        </descriptors>
                    </configuration>
                    <executions>
                        <execution>
                            <id>assembly</id>
                            <goals>
                                <goal>single</goal>
                            </goals>
                        </execution>
                    </executions>
                </plugin>
            </plugins>
    </build>


A descriptor.xml example:

<?xml version="1.0" encoding="UTF-8"?>
<assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2"
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          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>binary</id>
    <formats>
        <format>tar.gz</format>
    </formats>

    <includeBaseDirectory>true</includeBaseDirectory>
    <baseDirectory>${project.artifactId}-${project.version}</baseDirectory>

    <dependencySets>
         <dependencySet>
            <outputDirectory>/lib</outputDirectory>
           <includes>
                 <include>*:exernallib*</include>
           </includes>
         </dependencySet>
    </dependencySets>

   <componentDescriptors>
         <componentDescriptor>path/component.xml</componentDescriptor>
   </componentDescriptors>

    <fileSets>
        <fileSet>
            <directory>
                src/main/resources/lib
            </directory>
            <outputDirectory>${project.artifactId}-workflow/lib</outputDirectory>
        </fileSet>

        <fileSet>
            <directory>
                src/main/resources/scripts/sqoop
            </directory>
            <includes>
                <include>sqoop_param.txt</include>
            </includes>
            <outputDirectory>${project.artifactId}-workflow/</outputDirectory>
            <filtered>true</filtered>
            <fileMode>0744</fileMode>
        </fileSet>

        <fileSet>
            <directory>
                src/main/resources/job/
            </directory>
            <includes>
                <include>job.properties</include>
            </includes>
            <outputDirectory>.</outputDirectory>
        </fileSet>
    </fileSets>
</assembly>

Reference:
http://maven.apache.org/plugins/maven-assembly-plugin/
http://maven.apache.org/plugins/maven-assembly-plugin/descriptor-refs.html
http://maven.apache.org/plugins/maven-assembly-plugin/assembly.html
http://maven.apache.org/plugins/maven-assembly-plugin/examples/single/index.html

No comments:

Post a Comment