Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Migrated to Confluence 5.3

Scenario

You have a plugin that you want to add to two phases: test, and deploy. The test-phase binding should always run, but the deploy-phase binding should be optional.

How-To

Simply put the deploy-phase binding into a profile.

Code Block
xml
xml
<project>
  [...]
  <build>
    <plugins>
      <plugin>
        <groupId>some.plugin.group</groupId>
        <artifactId>my-maven-plugin</artifactId>
        <executions>
          <execution>
            <id>test-1</id>
            <phase>test</phase>
            <goals>
              <goal>do-stuff</goal>
            </goals>
            <configuration>
              <param>value</param>
            </configuration>
          </execution>
          <execution>
            <id>test-2</id>
            <phase>test</phase>
            <goals>
              <goal>do-stuff</goal>
            </goals>
            <configuration>
              <param>value2</param>
            </configuration>
          </execution>
          <execution>
            <id>test-n</id>
            <phase>test</phase>
            <goals>
              <goal>do-stuff</goal>
            </goals>
            <configuration>
              <param>valueN</param>
            </configuration>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>

  <profiles>
    <profile>
      <id>deploy-optional</id>
      <build>
        <plugins>
          <plugin>
            <groupId>some.plugin.group</groupId>
            <artifactId>my-maven-plugin</artifactId>
            <executions>
              <execution>
                <id>deploy-1</id>
                <phase>deploy</phase>
                <goals>
                  <goal>do-stuff</goal>
                </goals>
                <configuration>
                  <param>value-deploy</param>
                </configuration>
              </execution>
              <execution>
                <id>deploy-2</id>
                <phase>deploy</phase>
                <goals>
                  <goal>do-stuff</goal>
                </goals>
                <configuration>
                  <param>value-deploy-2</param>
                </configuration>
              </execution>
              <execution>
                <id>deploy-n</id>
                <phase>deploy</phase>
                <goals>
                  <goal>do-stuff</goal>
                </goals>
                <configuration>
                  <param>value-deploy-N</param>
                </configuration>
              </execution>
            </executions>
          </plugin>
        </plugins>
      </build>
    </profile>
  </profiles>
</project>

Run It!

Under normal circumstances, you don't want the optional deployment bindings to execute, so you simply use:

No Format
mvn deploy

However, in some cases, you want to run the extra deploy-phase mojo bindings. To do this, run:

No Format
mvn \-P deploy-optional deploy