Search code examples
mavendockermaven-release-plugin

maven-release-plugin automatically run a script before commit


I was wondering if it would be possible to make the maven-release-plugin run a specific script before the commit of the new tag.

The reason is, I have a Dockerfile that I want to update with the new version of my project.


Solution

  • You could use the completionGoals option of the release:perform goal:

    Goals to run on completion of the preparation step, after transformation back to the next development version but before committing. Space delimited.

    And have the maven-exec-plugin execute your script via its exec goal.

    A simple example would be as following:

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

    Note the value of the completionGoals above, we actually telling Maven to also execute the exec plugin and its exec goal, which will then pick up our global configuration as above.

    In your case the exec configuration above would be something like:

    <configuration>
        <executable>your-script</executable>
        <!-- optional -->
        <workingDirectory>/tmp</workingDirectory>
        <arguments>
            <argument>-X</argument>
            <argument>myproject:dist</argument>
        </arguments>
    </configuration>
    

    Depending on the exact point of release preparation, you could also consider to use the additional preparationGoals configuration option instead:

    Goals to run as part of the preparation step, after transformation but before committing. Space delimited.

    Which has a default value of clean verify, in this case would then be clean verify exec:exec.