Maven 2.x Assembly Plugin

Sharing a default assembly descriptor across sub modules

Details

  • Type: New Feature New Feature
  • Status: Closed Closed
  • Priority: Major Major
  • Resolution: Fixed
  • Affects Version/s: 2.0.1
  • Fix Version/s: 2.2-beta-2
  • Component/s: None
  • Labels:
    None
  • Number of attachments :
    0

Description

I have a multi-project folders setup like one shown below,

root

_ sub-folder1
_ sub-folder2
_ sub-folder3
_ etc

Have a root pom.xml at the root folder level and in that I have defined
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<descriptors>
<descriptor>src/main/assembly/descriptor.xml
</descriptor>
</descriptors>
</configuration>
</plugin>

Above descriptor works fine only if I have defined a descriptor file on the src/main/assembly folder for each sub-folder1, sub-folder2, etc.
It would be great if maven supports me in defining a common assembly descriptor and can be shared by all the sub modules from a common location.

Issue Links

Activity

Hide
John Casey added a comment -

I just enabled this feature, with a slightly different solution. What you're really talking about is a standard assembly descriptor for more than one project. If your descriptor were built into the assembly plugin, it'd simply be a standard descriptorRef configuration. To enable this sort of behavior for standardized descriptors outside the assembly plugin itself, you can do the following:

Define a project that contains the standardized descriptor. Here's an example layout based on the integration test in:

http://svn.apache.org/repos/asf/maven/plugins/maven-assembly-plugin/src/it/basic-features/assemblyDescriptor-artifact

The pom.xml looks like this:

<project>
  <modelVersion>4.0.0</modelVersion>
  <parent>
    <groupId>org.test</groupId>
    <artifactId>assemblyDescriptor-artifact</artifactId>
    <version>1</version>
  </parent>
  
  <artifactId>descriptor</artifactId>
  <packaging>assembly-descriptor</packaging>
  <build>
    <extensions>
      <extension>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-assembly-artifact-types</artifactId>
        <version>2.2-beta-2-SNAPSHOT</version>
      </extension>
    </extensions>

    <plugins>
      <plugin>
        <artifactId>maven-assembly-plugin</artifactId>
        <version>2.2-beta-2-SNAPSHOT</version>
      </plugin>
    </plugins>
  </build>
</project>

The assembly descriptor is in src/main/resources/assembly-descriptor.xml by default, and looks like this in the example:

<assembly>
  <id>fromArtifact</id>
  <formats>
    <format>dir</format>
  </formats>
  <includeBaseDirectory>false</includeBaseDirectory>
  <files>
    <file>
      <source>src/config/a/file.txt</source>
      <outputDirectory>a</outputDirectory>
      <filtered>true</filtered>
    </file>
    <file>
      <source>src/config/b/file.txt</source>
      <outputDirectory>b</outputDirectory>
      <destName>file.txt</destName>
      <filtered>true</filtered>
    </file>
  </files>
</assembly>

(so, pretty much normal).

You can use the standard descriptor after installing it into the repository with a pom.xml like the following:

<project>
  <modelVersion>4.0.0</modelVersion>
  <parent>
    <groupId>org.test</groupId>
    <artifactId>assemblyDescriptor-artifact</artifactId>
    <version>1</version>
  </parent>
  
  <artifactId>assembly</artifactId>
  
  <build>
    <filters>
      <filter>a.properties</filter>
    </filters>
        
    <plugins>
      <plugin>
        <artifactId>maven-assembly-plugin</artifactId>
        <version>2.2-beta-2-SNAPSHOT</version>
        <configuration>
          <descriptors>
            <descriptor>org.test:descriptor:1</descriptor>
          </descriptors>
        </configuration>
        <executions>
          <execution>
            <id>assembly</id>
            <phase>package</phase>
            <goals>
              <goal>single</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>
</project>

Note the extension in the standard descriptor's pom.xml.

Show
John Casey added a comment - I just enabled this feature, with a slightly different solution. What you're really talking about is a standard assembly descriptor for more than one project. If your descriptor were built into the assembly plugin, it'd simply be a standard descriptorRef configuration. To enable this sort of behavior for standardized descriptors outside the assembly plugin itself, you can do the following: Define a project that contains the standardized descriptor. Here's an example layout based on the integration test in: http://svn.apache.org/repos/asf/maven/plugins/maven-assembly-plugin/src/it/basic-features/assemblyDescriptor-artifact The pom.xml looks like this:
<project>
  <modelVersion>4.0.0</modelVersion>
  <parent>
    <groupId>org.test</groupId>
    <artifactId>assemblyDescriptor-artifact</artifactId>
    <version>1</version>
  </parent>
  
  <artifactId>descriptor</artifactId>
  <packaging>assembly-descriptor</packaging>
  <build>
    <extensions>
      <extension>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-assembly-artifact-types</artifactId>
        <version>2.2-beta-2-SNAPSHOT</version>
      </extension>
    </extensions>

    <plugins>
      <plugin>
        <artifactId>maven-assembly-plugin</artifactId>
        <version>2.2-beta-2-SNAPSHOT</version>
      </plugin>
    </plugins>
  </build>
</project>
The assembly descriptor is in src/main/resources/assembly-descriptor.xml by default, and looks like this in the example:
<assembly>
  <id>fromArtifact</id>
  <formats>
    <format>dir</format>
  </formats>
  <includeBaseDirectory>false</includeBaseDirectory>
  <files>
    <file>
      <source>src/config/a/file.txt</source>
      <outputDirectory>a</outputDirectory>
      <filtered>true</filtered>
    </file>
    <file>
      <source>src/config/b/file.txt</source>
      <outputDirectory>b</outputDirectory>
      <destName>file.txt</destName>
      <filtered>true</filtered>
    </file>
  </files>
</assembly>
(so, pretty much normal). You can use the standard descriptor after installing it into the repository with a pom.xml like the following:
<project>
  <modelVersion>4.0.0</modelVersion>
  <parent>
    <groupId>org.test</groupId>
    <artifactId>assemblyDescriptor-artifact</artifactId>
    <version>1</version>
  </parent>
  
  <artifactId>assembly</artifactId>
  
  <build>
    <filters>
      <filter>a.properties</filter>
    </filters>
        
    <plugins>
      <plugin>
        <artifactId>maven-assembly-plugin</artifactId>
        <version>2.2-beta-2-SNAPSHOT</version>
        <configuration>
          <descriptors>
            <descriptor>org.test:descriptor:1</descriptor>
          </descriptors>
        </configuration>
        <executions>
          <execution>
            <id>assembly</id>
            <phase>package</phase>
            <goals>
              <goal>single</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>
</project>
Note the extension in the standard descriptor's pom.xml.
Hide
Grégory Joseph added a comment -

Would there be a way to filter the assembly descriptor itself, based on properties from the project/pom using it ?

Show
Grégory Joseph added a comment - Would there be a way to filter the assembly descriptor itself, based on properties from the project/pom using it ?
Hide
Wouter Hermeling added a comment -

I'm confused. Why not choose for uploading the assembly descriptor in a repository like it is done for the site.xml of the site plugin???

With this solution:

  • If i want to use the solution above, i have to change the packaging of my parent project to: assembly-descriptor
  • i cannot to reuse an assembly descriptor in another project (with a different parent pom hierarchy

NOTE: Since i require this functionality, i might implement a site-plugin like solution and post the patch here.

Show
Wouter Hermeling added a comment - I'm confused. Why not choose for uploading the assembly descriptor in a repository like it is done for the site.xml of the site plugin??? With this solution:
  • If i want to use the solution above, i have to change the packaging of my parent project to: assembly-descriptor
  • i cannot to reuse an assembly descriptor in another project (with a different parent pom hierarchy
NOTE: Since i require this functionality, i might implement a site-plugin like solution and post the patch here.
Hide
Grégory Joseph added a comment -

John, wouldn't it be possible to bundle multiple assemblies in a single artifact ? On a related note, how can components be (re)used in the context of "artifact'ed" assemblies ?

Show
Grégory Joseph added a comment - John, wouldn't it be possible to bundle multiple assemblies in a single artifact ? On a related note, how can components be (re)used in the context of "artifact'ed" assemblies ?
Hide
Kaizer Sogiawala added a comment -

What are the plans of releasing maven-assembly-artifact-types:2.2-beta-2 ?
I see maven-assembly-plugin:2.2-beta-2 is already available

Show
Kaizer Sogiawala added a comment - What are the plans of releasing maven-assembly-artifact-types:2.2-beta-2 ? I see maven-assembly-plugin:2.2-beta-2 is already available
Hide
Grégory Joseph added a comment - - edited

I surprisingly had to add

<configuration>
          <ignoreMissingDescriptor>true</ignoreMissingDescriptor>
</configuration>
to the assembly plugin configuration when trying this again today. How come this could have changed ? (i updated my maven deps to 2.0.9 but I'm don't really see how that would have modified this behaviour)

Also, a little bump on the question above.

Show
Grégory Joseph added a comment - - edited I surprisingly had to add
<configuration>
          <ignoreMissingDescriptor>true</ignoreMissingDescriptor>
</configuration>
to the assembly plugin configuration when trying this again today. How come this could have changed ? (i updated my maven deps to 2.0.9 but I'm don't really see how that would have modified this behaviour) Also, a little bump on the question above.
Hide
John Casey added a comment -

There's a much simpler way to accomplish all this. In fact, I've even moved away from using the descriptor and component packaging types in favor of it. Simply put all your standardized descriptors, components, etc. into a normal jar project, and install that project. The project directory might look something like this:

/ my-custom-assemblies
|   +- pom.xml
|   +- src
|   |   +- main
|   |   |   +- resources
|   |   |   |   +- assemblies
|   |   |   |   |   +- custom-one.xml
|   |   |   |   |   +- custom-two.xml

Then, in the plugin-level dependencies of the POM from which you want to create an assembly (or, it could be in the top-level POM for a bunch of projects you want to use the same assembly...you can get pretty creative using pluginManagement here), you simply reference that standardized assembly-descriptor project:

<build>
  <pluginManagement>
    <plugins>
      <plugin>
        <artifactId>maven-assembly-plugin</artifactId>
        <version>2.2-beta-2</version>
        <dependencies>
          <dependency>
            <groupId>org.myproject</groupId>
            <artifactId>my-custom-assemblies</artifactId>
            <version>1.0</version>
          </dependency>
        </dependencies>
        <executions>
          <execution>
            <id>make-assembly</id>
            <phase>package</phase>
            <goals>
              <goal>single</goal>
            </goals>
            <configuration>
              <descriptorRefs>
                <descriptorRef>custom-one.xml</descriptorRef>
                <descriptorRef>custom-two.xml</descriptorRef>
              </descriptorRefs>
            </configuration>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </pluginManagement>
</build>

Then, wherever you want a sub-module to create these two assemblies, you add this to the sub-module pom:

<build>
  <plugins>
    <plugin>
      <artifactId>maven-assembly-plugin</artifactId>
    </plugin>
  </plugins>
</build>
Show
John Casey added a comment - There's a much simpler way to accomplish all this. In fact, I've even moved away from using the descriptor and component packaging types in favor of it. Simply put all your standardized descriptors, components, etc. into a normal jar project, and install that project. The project directory might look something like this:
/ my-custom-assemblies
|   +- pom.xml
|   +- src
|   |   +- main
|   |   |   +- resources
|   |   |   |   +- assemblies
|   |   |   |   |   +- custom-one.xml
|   |   |   |   |   +- custom-two.xml
Then, in the plugin-level dependencies of the POM from which you want to create an assembly (or, it could be in the top-level POM for a bunch of projects you want to use the same assembly...you can get pretty creative using pluginManagement here), you simply reference that standardized assembly-descriptor project:
<build>
  <pluginManagement>
    <plugins>
      <plugin>
        <artifactId>maven-assembly-plugin</artifactId>
        <version>2.2-beta-2</version>
        <dependencies>
          <dependency>
            <groupId>org.myproject</groupId>
            <artifactId>my-custom-assemblies</artifactId>
            <version>1.0</version>
          </dependency>
        </dependencies>
        <executions>
          <execution>
            <id>make-assembly</id>
            <phase>package</phase>
            <goals>
              <goal>single</goal>
            </goals>
            <configuration>
              <descriptorRefs>
                <descriptorRef>custom-one.xml</descriptorRef>
                <descriptorRef>custom-two.xml</descriptorRef>
              </descriptorRefs>
            </configuration>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </pluginManagement>
</build>
Then, wherever you want a sub-module to create these two assemblies, you add this to the sub-module pom:
<build>
  <plugins>
    <plugin>
      <artifactId>maven-assembly-plugin</artifactId>
    </plugin>
  </plugins>
</build>
Hide
Grégory Joseph added a comment -

ha, excellent, works indeed and is simpler. The documentation for descriptorRefs doesn't make this obvious, tho.

Thanks !

Show
Grégory Joseph added a comment - ha, excellent, works indeed and is simpler. The documentation for descriptorRefs doesn't make this obvious, tho. Thanks !

People

Vote (1)
Watch (4)

Dates

  • Created:
    Updated:
    Resolved: