将exec-maven-plugin的输出分配给变量

时间:2013-07-31 06:33:30

标签: maven exec-maven-plugin

我想使用exec-maven-plugin来获取git'revision',所以我正在使用以下配置:

<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>

但我遇到了问题 - 如何将输出分配给其他插件/活塞中可用的任何变量?

(我能够使用gmaven-plugin和执行groovy脚本完成它,但我发现它有点矫枉过正/不那么优雅)

编辑: 供参考,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>

1 个答案:

答案 0 :(得分:0)

为了清晰解决使用groovy:

sum(column-to-be-totalled)