0

How do I run a simple command (or a shell script containing said command) during the maven build phase?

My specific case is I'd like to run the protocol buffer compiler (protoc) that generates a java class prior to the java compiler running.

I feel like it should possibly be part of the "process resources" phase of the build goal (see http://books.sonatype.com/mvnref-book/reference/lifecycle-sect-common-goals.html) but they only discuss copying files that happen to be shell scripts, not running a script.

taringamberini
  • 2,719
  • 21
  • 29
engineerC
  • 2,808
  • 17
  • 31

1 Answers1

1

One solution to your problem is to use the maven-antrun-plugin. That is what I use to build some scriptlike commands within a maven build:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-antrun-plugin</artifactId>
    <version>1.3</version>
    <executions>
        <execution>
            <phase>generate-sources</phase>
            <configuration>
                <tasks>
                    <echo message="basedir=${basedir}" />
                </tasks>
            </configuration>
            <goals>
                <goal>run</goal>
            </goals>
        </execution>
    </executions>
</plugin>

With this a simple echo task is started in the build phase generate-sources. So you could extent this solution to your needs.

I like this ant aproach more than e.g. the exec-maven-plugin because it is imho in a way more system independent. But thats a thing of preference.

wumpz
  • 8,257
  • 3
  • 30
  • 25