I want to execute shell commands from Maven's pom.xml

NareshKumar picture NareshKumar · Aug 16, 2010 · Viewed 165.4k times · Source

I want to execute Linux shell commands with Maven. Here is what I tried:

<plugin>  
  <groupId>org.codehaus.mojo</groupId> 
  <artifactId>exec-maven-plugin</artifactId> 
  <version>1.1.1</version> 
  <executions>
    <execution>
      <goals>
        <goal>exec</goal> 
      </goals>
    </execution>
  </executions>
  <configuration>
    <executable>hostname</executable> 
  </configuration>
</plugin>

Answer

Curtis picture Curtis · Aug 16, 2010

Here's what's been working for me:

<plugin>
  <artifactId>exec-maven-plugin</artifactId>
  <groupId>org.codehaus.mojo</groupId>
  <executions>
    <execution><!-- Run our version calculation script -->
      <id>Version Calculation</id>
      <phase>generate-sources</phase>
      <goals>
        <goal>exec</goal>
      </goals>
      <configuration>
        <executable>${basedir}/scripts/calculate-version.sh</executable>
      </configuration>
    </execution>
  </executions>
</plugin>