Maven exec bash script and save the result as a property

I am wondering if there is a Maven plugin that runs a bash script and stores its results in a property.

My actual use case is getting the original version of git. I found one plugin available on the Internet, but it did not look well tested, and it occurred to me that I needed a plugin as simple as the one in the title of this post. The plugin will look something like this:

<plugin>maven-run-script-plugin> <phase>process-resources</phase> <!-- not sure where most intelligent --> <configuration> <script>"git rev-parse HEAD"</script> <!-- must run from build directory --> <targetProperty>"properties.gitVersion"</targetProperty> </configuration> </plugin> 

Of course, you need to make sure that this happens before the property is required, and in my case I want to use this property to process the source file.

+4
source share
1 answer

I think you could use the gmaven plugin for this task:

 <plugin> <groupId>org.codehaus.gmaven</groupId> <artifactId>gmaven-plugin</artifactId> <version>1.4</version> <executions> <execution> <phase>initialize</phase> <goals> <goal>execute</goal> </goals> <configuration> <properties> <script>git rev-parse HEAD</script> </properties> <source> def command = project.properties.script def process = command.execute() process.waitFor() project.properties.gitVersion = process.in.text </source> </configuration> </execution> </executions> </plugin> 

After running this script, you can access the ${gitVersion} property.

+3
source

All Articles