maven-release-plugin 在提交之前自动运行脚本

Rla*_*que 5 maven maven-release-plugin docker

我想知道是否可以maven-release-plugin在提交新标签之前运行特定的脚本。

原因是,我有一个 Dockerfile,我想用我的项目的新版本更新它。

A_D*_*teo 3

您可以使用目标completionGoals选项release:perform

目标是在完成准备步骤、转换回下一个开发版本之后但提交之前运行。空格分隔。

maven-exec-plugin通过其exec目标执行您的脚本。

一个简单的例子如下:

<build>
    <plugins>
        ....
        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>exec-maven-plugin</artifactId>
            <version>1.5.0</version>
            <configuration>
                <!-- example: executing an hello message on Windows console -->
                <executable>cmd</executable>
                <arguments>
                    <argument>/C</argument>
                    <argument>echo</argument>
                    <argument>hello</argument>
                </arguments>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-release-plugin</artifactId>
            <version>2.5.3</version>
            <configuration>
                ...
                <completionGoals>exec:exec</completionGoals>
            </configuration>
        </plugin>
    </plugins>
</build>
Run Code Online (Sandbox Code Playgroud)

请注意上面的值completionGoals,我们实际上告诉 Maven 也执行exec插件及其exec目标,然后它将获取上面的全局配置。

在您的情况下,上面的 exec 配置将类似于:

<configuration>
    <executable>your-script</executable>
    <!-- optional -->
    <workingDirectory>/tmp</workingDirectory>
    <arguments>
        <argument>-X</argument>
        <argument>myproject:dist</argument>
    </arguments>
</configuration>
Run Code Online (Sandbox Code Playgroud)

根据发布准备的具体点,您还可以考虑使用附加preparationGoals配置选项:

作为准备步骤的一部分运行的目标,在转换之后但在提交之前。空格分隔。

其默认值为clean verify,在本例中将为clean verify exec:exec