Rlarroque
Rlarroque

Reputation: 2050

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.

Upvotes: 5

Views: 1810

Answers (2)

michael_bitard
michael_bitard

Reputation: 4262

You could do like @dimatteo said, but I encourage you to NOT do this, as docker and maven are two tools for two differents purposes.

If you want to automate these 2 actions, use something (shell, jenkins, ...) which will launch maven then docker.

Upvotes: 1

A_Di-Matteo
A_Di-Matteo

Reputation: 27862

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.

Upvotes: 3

Related Questions