Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does exec-maven-plugin run all phases twice?

Tags:

maven

When I run a build with maven using the exec-maven-plugin, it runs everything twice for some reason. Is there a way to fix this so it only runs once? I've tried setting my phase in the pom.xml to compile and package and either way, it runs twice. My pom looks like

<build>
  <plugins>
    <plugin>
      <artifactId>exec-maven-plugin</artifactId>
      <groupId>org.codehaus.mojo</groupId>
      <version>1.0</version>
      <executions>
        <execution>
          <id>foo</id>
          <phase>compile</phase>
          <goals>
            <goal>exec</goal>
          </goals>
        </execution>
      </executions>
      <configuration>
        <executable>bash</executable>
        <commandlineArgs>myscript.sh</commandlineArgs>
      </configuration>
     </plugin>
    </plugins>
  </build>
like image 432
Thundercleez Avatar asked Dec 19 '25 09:12

Thundercleez


2 Answers

It turned out that adding the phase tag caused the command to get executed twice. Leaving that out, it is now getting run once as expected. I guess it doesn't matter what phase I give it now, it'll always run the goal, which works for me.

like image 120
Thundercleez Avatar answered Dec 22 '25 09:12

Thundercleez


If you need to run this early in the build, excluding the phase isn't an option.

You can do something like this instead in the plugin config:

<executions>
    <execution>
        <id>default</id>
        <phase>none</phase> <!-- disable the default execution in validate phase -->
    </execution>
    <execution>
        <id>exec-do-something</id>
        <goals>
            <goal>java</goal>
        </goals>
        <phase>generate-sources</phase><!-- now it will run once but in an earlier phase -->
    </execution>
</executions>
like image 28
Logan Waggoner Avatar answered Dec 22 '25 07:12

Logan Waggoner



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!