我想知道是否存在运行bash脚本的Maven插件并将其结果保存到属性中。
我的实际用例是获取git源代码版本。我发现一个在线可用的插件,但它看起来没有经过良好测试,我想到一个插件就像这篇文章标题中的插件一样简单就是我需要的。插件看起来像:
<plugin>maven-run-script-plugin>
<phase>process-resources</phase> <!-- not sure where most intelligent -->
<configuration>
<script>"git rev-parse HEAD"</script> <!-- must run from build directory -->
<targetProperty>"properties.gitVersion"</targetProperty>
</configuration>
</plugin>
当然需要确保在需要属性之前发生这种情况,在我的情况下,我想使用此属性来处理源文件。
答案 0 :(得分:4)
我认为您可以使用gmaven
插件执行此任务:
<plugin>
<groupId>org.codehaus.gmaven</groupId>
<artifactId>gmaven-plugin</artifactId>
<version>1.4</version>
<executions>
<execution>
<phase>initialize</phase>
<goals>
<goal>execute</goal>
</goals>
<configuration>
<properties>
<script>git rev-parse HEAD</script>
</properties>
<source>
def command = project.properties.script
def process = command.execute()
process.waitFor()
project.properties.gitVersion = process.in.text
</source>
</configuration>
</execution>
</executions>
</plugin>
执行此脚本后,您应该能够引用${gitVersion}
属性。