I want to have two scripts run from maven, one of which depends on an environment variable. I'm trying something like this:
<build>
<plugins>
<plugin>
<groupId>org.codehaus.groovy.maven</groupId>
<artifactId>gmaven-plugin</artifactId>
<version>1.0</version>
<executions>
<execution>
<phase>validate</phase>
<goals>
<goal>execute</goal>
</goals>
<configuration>
<source>
println "My script"
</source>
</configuration>
</execution>
</executions>
</plugin>
</build>
...
<profile>
<activation>
<property>
<name>env.MY_ENV_VAR</name>
<value>runStuff</value>
</property>
</activation>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.groovy.maven</groupId>
<artifactId>gmaven-plugin</artifactId>
<version>1.0</version>
<executions>
<execution>
<phase>validate</phase>
<goals>
<goal>execute</goal>
</goals>
<configuration>
<source>
println "My conditional script"
</source>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
When I run "mvn validate" to test this, I get "My script". When I set the env variable and run it again, I get "My conditional script" but not "My script". It seems that if the condition is satisfied and the second one runs, the first one will not.
I want to run the first one unconditionally and the second one only if the env variable is set. I thought of checking the env variable in the script itself but that seems problematic too, according to this question.
I'm new to maven so it's not unlikely there's a simple solution but I'm not seeing it.
I found the answer. Each execution must have a unique ID. If you don't specify an ID, you get 'default' for both. Once I gave the conditional one a non-default ID, they both run.
<build>
<plugins>
<plugin>
...
<executions>
<execution>
<id>Unconditional-script</id>
...
</execution>
</executions>
</plugin>
</build>
...
<profile>
...
<build>
<plugins>
<plugin>
...
<executions>
<execution>
<id>Conditional-script</id>
...
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>