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

问题描述 投票:7回答:1

我想使用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>

但我遇到了一个问题 - 如何将输出分配给其他插件/ livecycles中的任何变量?

(我能够使用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>
maven exec-maven-plugin
1个回答
0
投票

为了清晰使用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>
© www.soinside.com 2019 - 2024. All rights reserved.