views:

186

answers:

1

I have a number of maven projects which build various components of a plugin framework for a 3rd party application. I have a master project which, using aggregation ( element), includes all the sub projects. This master project also calls the maven assembler plugin. I can now build all the sub-projects and have the assembler copy their outputs/files/sources/resources etc into a master build directory, and then zip all these files up into a single distribution zip. I do this with the command:

mvn package assembly:assembly

This all works great. I now want to pass this zip file into another maven plugin which will open it up and create a custom manifest file which lists the zip contents and then insert this manifest file back into the zip file. I have written the plugin to do this and it works fine.

My problem is getting this plugin run by maven as part of the build process.

The plugin need the output from the assembler, but there doesn't seem to be anyway of running a plugin after the assembler.

Can anyone help?

+1  A: 

Assuming the assembly has already been defined to create the assembly in target/assemblies, you simply need to bind the execution of the plugins to phases of the standard lifecycle, so you can run mvn install (for example) and have the plugins executed during that lifecycle.

  <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-assembly-plugin</artifactId>
    <executions>
      <execution>
        <id>generate-assembly</id>
        <phase>package</phase>
        <goals>
          <goal>single</goal>
        </goals>
        <configuration>
          <!--your configuration here -->
          ...
        </configuration>
      </execution>
    </executions>
  </plugin>

You then bind the execution of your plugin to a later phase (say integration-test), so that it is able to access the assembly files:

  <plugin>
    <groupId>your.plugin.groupId</groupId>
    <artifactId>your-artifactId</artifactId>
    <executions>
      <execution>
        <id>mung-manifests</id>
        <phase>package</phase>
        <goals>
          <goal>your-goal-name</goal>
        </goals>
        <configuration>
          <assemblyDirectory>${project.build.directory}/assemblies</assemblyDirectory>
        </configuration>
      </execution>
    </executions>
  </plugin>

Using this approach each plugin will be executed in the relevant phase (package) when you run mvn package (or later phase such as install, verify, deploy...).

Note that your plugin should be defined after the assembly plugin to ensure it is executed afterwards (it doesn't matter about order if they're in different phases, only when in the same phase).

Rich Seller