Using maven assembler plugin output as plugin input

I have several maven projects that create various plugin components for a third party application. I have a master project which, using aggregation (<modules> element), includes all sub projects. This master project also calls the maven assembler plugin. Now I can collect all sub-projects and copy their outputs / files / sources / resources etc. Into the master build directory and then zip all these files into one zip distribution. I do this with the command:

mvn build: build

This all works great. Now I want to pipe this zip file to another maven plugin which will open it and create its own manifest file which will list the zip content and then paste this manifest file back into the zip file. I wrote a plugin for this and it works great.

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

The plugin needs output from the assembler, but there doesn't seem to be a plugin after the assembler.

Can anyone please help?

+2


source to share


1 answer


Assuming an assembly is already defined to create an assembly in the target / assemblies, you just need to associate the plugins execution with the 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>

      

Then you link the execution of your plugin to a later phase (say an integration test) so that it can access the build 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 its respective phase (package) when you run mvn package

(or a later phase like install, checkout, deploy ...).

Note that your plugin must be defined after the build plugin to ensure it gets executed after that (it doesn't matter for order if they are in different phases, only in the same phase).

+1


source







All Articles