Exec Plugin

Example that shows build phases with the exec plugin.

  • $ mvn clean
    • Runs Script run.sh at clean.
    • Creates dummy.txt with “cleaning” .
  • $ mvn package
    • Runs Script run.sh at initialize.
    • Creates dummy.txt with “Hello World!” .

pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>

  <groupId>nl.ersoftware</groupId>
  <artifactId>exec-plugin</artifactId>
  <version>1.0-SNAPSHOT</version>

  <packaging>pom</packaging>

  <build>
    <plugins>
      <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>exec-maven-plugin</artifactId>
        <version>3.1.0</version>
        <executions>

          <execution>
            <id>Run script at clean</id>
            <phase>clean</phase>
            <goals>
              <goal>exec</goal>
            </goals>
            <configuration>
              <executable>run.sh</executable>
              <arguments>
                <argument>cleaning</argument>
              </arguments>
            </configuration>
          </execution>

          <execution>
            <id>Run Script at initialize</id>
            <phase>initialize</phase>
            <goals>
              <goal>exec</goal>
            </goals>
            <configuration>
              <executable>run.sh</executable>
              <arguments>
                <argument>Hello </argument>
                <argument>World!</argument>
              </arguments>
            </configuration>
          </execution>

        </executions>
      </plugin>
    </plugins>
  </build>
</project>

run.sh

#!/bin/sh

echo $* >> dummy.txt