| ------ |
| Guide to Creating Assemblies |
| ------ |
| Jason van Zyl |
| ------ |
| 2005-10-12 |
| ------ |
| |
| ~~ Licensed to the Apache Software Foundation (ASF) under one |
| ~~ or more contributor license agreements. See the NOTICE file |
| ~~ distributed with this work for additional information |
| ~~ regarding copyright ownership. The ASF licenses this file |
| ~~ to you under the Apache License, Version 2.0 (the |
| ~~ "License"); you may not use this file except in compliance |
| ~~ with the License. You may obtain a copy of the License at |
| ~~ |
| ~~ http://www.apache.org/licenses/LICENSE-2.0 |
| ~~ |
| ~~ Unless required by applicable law or agreed to in writing, |
| ~~ software distributed under the License is distributed on an |
| ~~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| ~~ KIND, either express or implied. See the License for the |
| ~~ specific language governing permissions and limitations |
| ~~ under the License. |
| |
| ~~ NOTE: For help with the syntax of this file, see: |
| ~~ http://maven.apache.org/doxia/references/apt-format.html |
| |
| Guide to creating assemblies |
| |
| The assembly mechanism in Maven provides an easy way to create distributions using a assembly descriptor |
| and dependency information found in you POM. In order to use the assembly plug-in you need to configure the |
| assembly plug-in in your POM and it might look like the following: |
| |
| +----+ |
| <project> |
| <parent> |
| <artifactId>maven</artifactId> |
| <groupId>org.apache.maven</groupId> |
| <version>2.0-beta-3-SNAPSHOT</version> |
| </parent> |
| <modelVersion>4.0.0</modelVersion> |
| <groupId>org.apache.maven</groupId> |
| <artifactId>maven-embedder</artifactId> |
| <name>Maven Embedder</name> |
| <version>2.0-beta-3-SNAPSHOT</version> |
| <build> |
| <plugins> |
| <plugin> |
| <artifactId>maven-assembly-plugin</artifactId> |
| <version>2.5.3</version> |
| <configuration> |
| <descriptor>src/assembly/dep.xml</descriptor> |
| </configuration> |
| <executions> |
| <execution> |
| <id>create-archive</id> |
| <phase>package</phase> |
| <goals> |
| <goal>single</goal> |
| </goals> |
| </execution> |
| </executions> |
| </plugin> |
| </plugins> |
| </build> |
| ... |
| </project> |
| +----+ |
| |
| You'll notice that the assembly descriptor is located in <<<$\{project.basedir\}/src/assembly>>> which is the |
| {{{../introduction/introduction-to-the-standard-directory-layout.html}standard}} location for assembly |
| descriptors. |
| |
| * Creating a binary assembly |
| |
| This is the most typical usage of the assembly plugin where you are creating a distribution for standard |
| use. |
| |
| +----+ |
| <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>bin</id> |
| <formats> |
| <format>tar.gz</format> |
| <format>tar.bz2</format> |
| <format>zip</format> |
| </formats> |
| <fileSets> |
| <fileSet> |
| <directory>${project.basedir}</directory> |
| <outputDirectory>/</outputDirectory> |
| <includes> |
| <include>README*</include> |
| <include>LICENSE*</include> |
| <include>NOTICE*</include> |
| </includes> |
| </fileSet> |
| <fileSet> |
| <directory>${project.build.directory}</directory> |
| <outputDirectory>/</outputDirectory> |
| <includes> |
| <include>*.jar</include> |
| </includes> |
| </fileSet> |
| <fileSet> |
| <directory>${project.build.directory}/site</directory> |
| <outputDirectory>docs</outputDirectory> |
| </fileSet> |
| </fileSets> |
| </assembly> |
| +----+ |
| |
| You can use a manually defined assembly descriptor as mentioned before but it is simpler to use the |
| {{{/plugins/maven-assembly-plugin/descriptor-refs.html#bin}pre-defined assembly descriptor bin}} |
| in such cases. |
| |
| How to use such pre-defined assembly descriptors is described in the |
| {{{/plugins/maven-assembly-plugin/usage.html#Configuration}documentation of maven-assembly-plugin}}. |
| |
| +----+ |
| <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"> |
| |
| <!-- TODO: a jarjar format would be better --> |
| <id>dep</id> |
| <formats> |
| <format>jar</format> |
| </formats> |
| <includeBaseDirectory>false</includeBaseDirectory> |
| <fileSets> |
| <fileSet> |
| <outputDirectory>/</outputDirectory> |
| </fileSet> |
| </fileSets> |
| <dependencySets> |
| <dependencySet> |
| <outputDirectory>/</outputDirectory> |
| <unpack>true</unpack> |
| <scope>runtime</scope> |
| <excludes> |
| <exclude>junit:junit</exclude> |
| <exclude>commons-lang:commons-lang</exclude> |
| <exclude>commons-logging:commons-logging</exclude> |
| <exclude>commons-cli:commons-cli</exclude> |
| <exclude>jsch:jsch</exclude> |
| <exclude>org.apache.maven.wagon:wagon-ssh</exclude> |
| <!-- TODO: can probably be removed now --> |
| <exclude>plexus:plexus-container-default</exclude> |
| </excludes> |
| </dependencySet> |
| </dependencySets> |
| </assembly> |
| |
| +----+ |
| |
| If you like to create a source distribution package the best solution is to use the |
| {{{/plugins/maven-assembly-plugin/descriptor-refs.html#src}pre-defined assembly descriptor src}} |
| for such purposes. |
| |
| +----+ |
| <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>src</id> |
| <formats> |
| <format>tar.gz</format> |
| <format>tar.bz2</format> |
| <format>zip</format> |
| </formats> |
| <fileSets> |
| <fileSet> |
| <directory>${project.basedir}</directory> |
| <includes> |
| <include>README*</include> |
| <include>LICENSE*</include> |
| <include>NOTICE*</include> |
| <include>pom.xml</include> |
| </includes> |
| <useDefaultExcludes>true</useDefaultExcludes> |
| </fileSet> |
| <fileSet> |
| <directory>${project.build.sourceDirectory}/src</directory> |
| <useDefaultExcludes>true</useDefaultExcludes> |
| </fileSet> |
| </fileSets> |
| </assembly> |
| +----+ |
| |
| You can now create the defined distribution packages via command line like this: |
| |
| +----+ |
| mvn package |
| +----+ |
| |