Assign the output of exec-maven-plugin to a variable

I want to use exec-maven-plugin to get git 'revision', so I use the following configuration:

<plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>exec-maven-plugin</artifactId> <version>1.2.1</version> <executions> <execution> <id>gitVersion</id> <phase>validate</phase> <goals> <goal>exec</goal> </goals> </execution> </executions> <configuration> <executable>git</executable> <workingDirectory>./</workingDirectory> <arguments> <argument>rev-list</argument> <argument>master</argument> <argument>--count</argument> </arguments> </configuration> </plugin> 

but I ran into a problem - how to assign output to any variable available in other plugins / livecycles?

(I managed to do this with gmaven-plugin and execute a groovy script, but I find it a little redundant / less elegant)

EDIT: for reference, working solution in groovy:

 <plugin> <groupId>org.codehaus.gmaven</groupId> <artifactId>gmaven-plugin</artifactId> <version>1.5</version> <executions> <execution> <phase>validate</phase> <goals> <goal>execute</goal> </goals> <configuration> <providerSelection>2.0</providerSelection> <properties> <script>git rev-list master --count</script> </properties> <source> def command = project.properties.script def process = command.execute() process.waitFor() def describe = process.in.text.trim() println "setting revision to: " + describe project.properties.setProperty('gitVersion',describe) </source> </configuration> </execution> </executions> </plugin> 
+6
source share

Source: https://habr.com/ru/post/950687/


All Articles