Run a script after maven install

12,041

Solution 1

Use the http://www.mojohaus.org/exec-maven-plugin/ exec-maven-plugin, in conjunction with an "executions" configuration block that specifies the installation phase. Make sure it is after your maven-install-plugin as plugins are ran in order (within the same phase)

(in build/plugins)  
  <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-install-plugin</artifactId>
    <version>2.5.2</version>
  </plugin>
  <plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>exec-maven-plugin</artifactId>
    <version>1.5.0</version>
    <executions>
      <execution>
        <phase>install</phase>
        <goals>
           <goal>exec</goal>
        </goals>
        <configuration>
          <executable>do-something.sh</executable>
          <workingDirectory>/some/dir</workingDirectory>
          <arguments>
             <argument>--debug</argument>
             <argument>with_great_effect</argument>
          </arguments>
        </configuration>
      </execution>
    </executions>
  </plugin>

Solution 2

For a purely maven-driven approach, the answer you're looking for is the exec goal of exec-maven-plugin, and this answer applies: https://stackoverflow.com/a/2008258/3403663

EDIT: OP indicates the above doesn't work for him.

Alternative approach: I just tried the following in my own project, and it executes ls at the very end of the install phase, after artifacts have been deployed.

mvn clean install exec:exec -Dexec.executable="/bin/ls" -Dexec.args="/etc"

Otherwise, you could always just wrap the whole thing in a script:

#!/bin/bash

set -o errexit

mvn clean install
<your other commands here>
Share:
12,041
Dorin
Author by

Dorin

Updated on June 04, 2022

Comments

  • Dorin
    Dorin almost 2 years

    I have a Maven project and after I install the project I need to run a script. I want to automize this process. My guess is that by adding something in the pom file I could automize this, but so far i haven't found how to run a script after installation. I only found how to run a script before the maven project has finised installing.

    So, how can I run a script after a Maven project as finished installing?

  • Dorin
    Dorin over 7 years
    Thanks for your response. But I want a pom configuration, if this is posible.
  • Dorin
    Dorin over 7 years
    The solution from the link doesn't work, the script is run before maven install., Thanks for your response.
  • Dorin
    Dorin over 7 years
    I trired to put this in the build tag from pom and the script run before maven install finished installing.
  • Edwin Buck
    Edwin Buck over 7 years
    There's an exec plugin, seriously don't chain to ant to have ant chain to exec.
  • Edwin Buck
    Edwin Buck over 7 years
    Don't include ant configurations just to do stuff there's maven plugins for. That makes your configuration maintenance include support for both Maven and Ant!