5

bash スクリプトを実行し、その結果をプロパティに保存する Maven プラグインが存在するかどうか疑問に思っています。

私の実際の使用例は、git ソース バージョンを取得することです。オンラインで入手できるプラグインを 1 つ見つけましたが、十分にテストされているようには見えず、この投稿のタイトルにあるような単純なプラグインで十分だと思いました。プラグインは次のようになります。

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

もちろん、プロパティが必要になる前にこれが確実に行われるようにする必要があります。私の場合は、このプロパティを使用してソース ファイルを処理したいと考えています。

4

1 に答える 1

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}プロパティを参照できるようになります。

于 2012-12-15T08:31:35.333 に答える