Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Maven Release Perform Commit Additional Files

I am using the preparationGoals configuration option of the Maven release plugin to transform additional files to reflect the version of the project being released. This works beautifully.

The problem is that when executing the commit, the plugin explicitly specifies that only the pom.xml files should be included thus leaving my other files uncommited:

[INFO] Executing: /bin/sh -c cd /Users/jw/dev/Test && git commit --verbose -F /var/folders/w0/hr1h_7h50f3_pwd_nrk9l808000195/T/maven-scm-114713951.commit pom.xml library/pom.xml sample/pom.xml

Is there any way for me to override this behavior and specify additional files or globs to include in the commit?

(I also need this behavior for the completionGoals as well which I have configured to do that same transformation)

like image 535
Jake Wharton Avatar asked Apr 15 '12 10:04

Jake Wharton


Video Answer


1 Answers

I also need to commit some additional files (changed by Maven Replacer plugin). I did it in the following way:

First I configured Maven Release plugin to execute additional goals:

<plugin>
    <artifactId>maven-release-plugin</artifactId>
    <version>2.5.3</version>
    <configuration>
        <preparationGoals>-Prelease -DreplacerVersion="${releaseVersion}" clean replacer:replace scm:checkin verify</preparationGoals>
        <completionGoals>-Prelease -DreplacerVersion="${developmentVersion}" clean replacer:replace scm:checkin verify</completionGoals>
    </configuration>
</plugin>
  • release profile defines configuration of Maven SCM plugin
  • replacerVersion argument is used by Maven Replacer plugin to set correct version in some files
  • clean is a standard goal run by Maven Release plugin (default: clean verify)
  • replacer:replace goal is responsible for modifying files
  • scm:checkin does commit and push
  • verify is a standard goal run by Maven Release plugin (default: clean verify)

Next I configured Maven Replacer plugin:

<plugin>
    <groupId>com.google.code.maven-replacer-plugin</groupId>
    <artifactId>replacer</artifactId>
    <version>1.5.3</version>
    <configuration>
        <includes>
            <include>${basedir}/file1.txt</include>
            <include>${basedir}/file2.txt</include>
        </includes>
        <replacements>
            <replacement>
                <token><![CDATA[<pattern>.*</pattern>]]></token>
                <value><![CDATA[<pattern>${replacerVersion}</pattern>]]></value>
            </replacement>
        </replacements>
    </configuration>
</plugin>

${replacerVersion} allows to use the same configuration for changing from a development to a release and next from the release to a next development version.

Finally I defined which version of Maven SCM plugin I want to use:

<plugin>
    <artifactId>maven-scm-plugin</artifactId>
    <version>1.9.5</version>
</plugin>

and configuration it in the release profile (I defined it in the profile to prevent accidental commits during non-release build):

<profile>
    <id>release</id>
    <build>
        <pluginManagement>
            <plugins>
                <plugin>
                    <artifactId>maven-scm-plugin</artifactId>
                    <configuration>
                        <message>[maven-scm-plugin] set ${replacerVersion} version in files</message>
                        <includes>file1.txt, file2.txt</includes>
                    </configuration>
                </plugin>
            </plugins>
        </pluginManagement>
    </build>
</profile>

Thanks to that after executing a command:

mvn release:prepare -DdevelopmentVersion=1.2.1-SNAPSHOT -DreleaseVersion=1.2.0 -Dtag=1.2.0

I see 4 commits:

  1. [maven-scm-plugin] set 1.2.0 version in files
  2. [maven-release-plugin] prepare release 1.2.0
  3. [maven-scm-plugin] set 1.2.1-SNAPSHOT version in files
  4. [maven-release-plugin] prepare for next development iteration
like image 74
agabrys Avatar answered Sep 18 '22 19:09

agabrys