gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-04 08:55:42 31 4
gpt4 key购买 nike

我想使用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脚本来完成它,但是我发现它有点过分/不太优雅)

编辑:
供引用,常规的工作解决方案:
<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>

最佳答案

为了清晰起见,使用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的输出分配给变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17963222/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com