views:

456

answers:

1

I've got a Maven assembly that I want to use in multiple projects. How do I reuse it without hardcoding the path?

+1  A: 

With the latest version of the assembly plugin (2.2-beta-2), you can use a [shared descriptor][1]. Define the descriptor in the src/main/resources/assemblies folder of a separate project and install or deploy it.

In the projects that want to use the descriptor, define a dependency on the descriptor project in the assembly plugin configuration, then reference the assembly.

Update: There is a special rule that checks the assemblies directory. So either /assemblies/myassembly.xml or just /myassembly.xml work as long as you're using the magic assemblies directory name. For other directory names the full path relative to the resources directory is needed.

I'd wrongly warned that there is an error in the referenced documentation and that the reference path needs to match the relative path below src/main resources, i.e. assemblies/myassembly.xml not assembly.xml.

The project using the shared descriptor should have this configuration:

<build>
  ...
  <plugins>
    ...
    <plugin>
      <artifactId>maven-assembly-plugin</artifactId>
      <version>2.2-beta-2</version>
      <!--declare plugin has a dependency on the descriptor project -->
      <dependencies>
        <dependency>
          <groupId>your.group.id</groupId>
          <artifactId>my-assembly-descriptor</artifactId>
          <version>1.0-SNAPSHOT</version>
        </dependency>
      </dependencies>
      <executions>
        <execution>
          <id>make-assembly</id>
          <phase>package</phase>
          <goals>
            <goal>single</goal>
          </goals>
          <configuration>
            <!-- This is where we use our shared assembly descriptor -->
            <descriptors>
              <descriptor>assemblies/myassembly.xml</descriptor>
            </descriptors>
          </configuration>
        </execution>
      </executions>
    </plugin>
  </plugins>
</build>
Rich Seller