I have a shell script that I want maven to source. I specifically want maven to source the file (source run.sh
) rather than just executing it (./run.sh
)
I have tried 2 different approaches with 2 different plugins and neither work:
<plugin>
<artifactId>exec-maven-plugin</artifactId>
<groupId>org.codehaus.mojo</groupId>
<executions>
<execution>
<id>source file</id>
<phase>process-resources</phase>
<goals>
<goal>exec</goal>
</goals>
<configuration>
<executable>source</executable>
<arguments>
<argument>./run.sh</argument>
</arguments>
</configuration>
</execution>
</executions>
</plugin>
and
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<groupId>org.apache.maven.plugins</groupId>
<executions>
<execution>
<id>source file</id>
<phase>process-resources</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<target>
<exec executable="source">
<arg value="./run.sh"/>
</exec>
</target>
</configuration>
</execution>
</executions>
</plugin>
They both fail saying that the command source
does not exist
I based my answer on @walyrious idea. I execute bash -c 'source run.sh; custom-script.sh'
in maven-antrun-plugin so that custom-script.sh
is in the same shell as the sourced run.sh
. Though, I think this maven execution is much cleaner than his answer:
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<groupId>org.apache.maven.plugins</groupId>
<executions>
<execution>
<id>source file</id>
<phase>process-resources</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<target>
<exec executable="bash">
<arg line="-c 'source run.sh; custom-script.sh'"/>
</exec>
</target>
</configuration>
</execution>
</executions>
</plugin>