Quantcast
Viewing all articles
Browse latest Browse all 5648

How to run a script only for top-level project using maven-antrun-plugin?

Hi,

I want to create a profile that can help me run an auto-generated script onto the target m/c. Since i would want this on a build m/c to be executed only once, i figured it would be better to keep this target in a separate profile. Here is what the skeleton looks like in my parent component's pom.xml (i chose parent component, because there are 3 or 4 sub components who would need this script's output).

    <profile>
      <id>run-script</id>
      <build>
        <plugins>
          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-antrun-plugin</artifactId>
            <version>${maven-antrun-plugin.version}</version>
            <configuration>
              <skipTests>false</skipTests>
            </configuration>
            <executions>
              <execution>
                <id>run-script</id>
                <phase>initialize</phase>
                <goals>
                  <goal>run</goal>
                </goals>
                <configuration>
                  <target>
                    <echo file="target/install-foo.sh">
................
                    </echo>
                    <exec executable="sh" dir="${basedir}" failonerror="true">
                      <arg line="target/install-foo.sh" />
                    </exec>
                  </target>
                </configuration>
              </execution>
            </executions>
          </plugin>
        </plugins>
      </build>
    </profile>

My problem is that this script gets executed for each and every sub component of the parent component. Is there a way to ensure that this script install-foo.sh is executed only once? I was running "mvn initialize -Prun-script" I tried with generate-sources phase as well and had the script running for all the sub-components. Any pointers will be very helpful.

Thanks,
-Sumit

Viewing all articles
Browse latest Browse all 5648

Trending Articles