Monday, April 27, 2009

Run maven plugin goal with lifecycle phase

Let’s say you have “assembly” plugin configured in you pom.

<project>
  [...]
  <build>
    <plugins>
      <plugin>
        <artifactId>maven-assembly-plugin</artifactId>
        <configuration>
          <descriptorRefs>
            <descriptorRef>jar-with-dependencies</descriptorRef>
          </descriptorRefs>
        </configuration>
      </plugin>
    </plugins>
  </build>
  [...]
</project>

And you want to run it after the lifecycel goal “install”.

You can run
$ mvn install assembly:assembly

It generates a jar file with name "<NAME>-<Version>-jar-with-dependencies.jar and the classes of dependency jar files are packaged in this jar file also. 

You can also attach the goal with the lifecycle phase

<project>
[...]
<build>
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
<executions>
<execution>
<id>simple-command</id>
<phase>package</phase>
<goals>
<goal>attached</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
[...]
</project>


The execution configuration will make sure that the assembly:attached goal is executed when the Maven lifecycle transitions to the package phase of the lifecycle.

No comments:

Post a Comment