------ Including Module Binaries ------ John Casey ------ 05-May-2006 ------ ~~ 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 Including Module Binaries * Warning <> Using the <<>> section of a <<>> definition involves some tricky considerations that are a result of the way Maven sorts and executes project builds within a multimodule context. Please read {{{../../faq.html#module-binaries}this FAQ entry}} if you decide to use them. <> The new (since 2.2) <<>> flag in the <<>> section allows you to consume module binaries from child modules in a multimodule build. This is an important to resolve the conflict between Maven's build ordering and the old approach to module binaries, where the assembly was build from the parent POM. Please read the FAQ entry above for more information, and read the documentation below (carefully!) to see the new approach in action. * Introduction It is common practice to create an assembly using the parent POM of a multimodule build. At times, you may want to ensure that this assembly also includes one or more of the module binaries. This example demonstrates how to include the artifact and dependencies of a module, under the directory <<>>>. * The Assembly Descriptor First, let's write an assembly descriptor to create this assembly. For the sake of clarity, this descriptor will be as simple as possible, only demonstrating the features described by this example. +---+ bin dir false true org.test:child1 modules/${artifactId} false +---+ This descriptor states that the assembly id should be <<>>, that the output format is a directory, and that the contents of the assembly should <> be contained within a directory named after the finalName of the top-level project. Furthermore, it states that we wish to include the artifact files for the module with a groupId of <<>> and an artifactId of <<>>, along with its dependency artifacts. These artifacts should be contained within the directory structure <<>> for this module, since the outputDirectory expression will be interpolated on a module-by-module basis. <>, notice the <> <<>> flag. This enables access to all projects in the current reactor (multimodule build), even from a child module. Using this flag, it's now possible to use a child module - sorted to the end of the multimodule build process using appropriate dependency declarations - to generate an assembly containing module binaries. * The POM Now, let's review the POM configuration necessary to enable the building of this assembly via the <<>> goal. First, let's look at the parent POM: +---+ 4.0.0 org.test parent 1.0 pom Parent child1 child2 child3 distribution maven-assembly-plugin ${project.version} src/assemble/bin.xml +---+ <> The last module - <<>> - is the child in which the assembly will be created. That POM looks like this: +---+ 4.0.0 org.test parent 1.0 distribution pom Distribution org.test child1 1.0 maven-assembly-plugin distro-assembly package single src/assemble/bin.xml +---+ This POM directs the Assembly Plugin to execute the <<>> goal when the build reaches the <<>> phase, and tells it to use the <<>> assembly descriptor when executing. * Execute! To build the assembly, we issue the following command: +---+ mvn clean package +---+ This will ensure that the output directory (normally, <<>>), is removed before building the assembly directory. <> Because of a quirk in Maven 2.0's execution model relating to aggregator goals and the inheritance hierarchy, we need to explicitly execute the package phase ahead of the assembly invocation, to ensure all modules have been built. * Examining the Output When the Maven execution completes, the following directory structure should be left. Remember, our assembly format was <<>>, which is why the output is a directory and not an archive of some sort. Here are the directory contents: +---+ target/distribution/distribution-1.0-bin `-- modules `-- child1 |-- child1-1.0.jar `-- junit-3.8.1.jar +---+