Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

assign output of exec-maven-plugin to variable

I want to use exec-maven-plugin to get git 'revision', so I'm using 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 hit a problem - how do I assign output to any variable available in other plugins/livecycles?

(I was able to get it done using gmaven-plugin and executing groovy script, but I find it a bit of overkill/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>
like image 300
Wojtek Avatar asked Jul 31 '13 06:07

Wojtek


1 Answers

Just for clarity, here's the solution using 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>
like image 189
Wojtek Avatar answered Nov 05 '22 16:11

Wojtek