Maven Release Executing Additional Files

I use the preparationGoals configuration parameter in the Maven release plugin to convert additional files to reflect the version of the project being released. It works great.

The problem is that when committing, the plugin explicitly indicates that only pom.xml files should be included, which leaves my other files inactive:

[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 a way to override this behavior and specify additional files or globs to be included in commit?

(I also need this behavior for completionGoals , which I configured to perform the same conversion)

+7
source share
3 answers

Could you use maven-scm-plugin ? Add a plugin that executes the scm:checkin to commit the necessary files. Bind it to the phase that will be executed during preparationGoals (if you specified one or more phases as a value for this element) or directly include the scm:checkin in preparationGoals .

+4
source

It seems that refusing to provide a specification for additional tag files is actually a mistake in Maven. Line 130 in the org.apache.maven.shared.release.phase.AbstractScmCommitPhase section of the Maven Release Plugin class contains references to the commitByProject flag, first introduced in Maven 2.0-beta-7.

Branching is used to determine the mechanism for adding files to the Maven: make commit release. The SCM plugin is loaded with files before committing using the SCMFileSet class . One of the instances of the branch of this class may have tried to add all the files to the base directory, but this does not work in SCM.

This is the point at which the patch can be implemented to get a list of files or to add a file directory for commit.

Below, after deeply immersing himself in the debugging execution of the Maven Release plugin, he calls the SCM plugin to add only POM from the repositories. Changing the poorly documented commitByProject flag has zero effect on the results for which files are added to the SCM commit.

0
source

I also need to commit some additional files (modified by the Maven Replacer plugin). I did it as follows:

First, I configured the Maven Release plugin to accomplish 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 plugin configuration Maven SCM Argument
  • replacerVersion used by the Maven Replacer plugin to install the correct version in some files.
  • clean - the standard target launched by the Maven Release plugin (default: clean verify )
  • replacer:replace The target is responsible for modifying files
  • scm:checkin commit and click
  • verify is the standard target executed by the Maven Release plugin (default: clean verify )

Next, I configured the 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> <replacement> </configuration> </plugin> 

${replacerVersion} allows you to use the same configuration to move from development to release and from version to the next development version.

Finally, I determined which version of the Maven SCM plugin I want to use:

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

and configure it in the release profile (I defined it in the profile to prevent accidental commit during build without release):

 <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 this, after executing the command:

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

I see 4 commits:

  • [maven-scm-plugin] install version 1.2.0 in files
  • [maven-release-plugin] prepare release 1.2.0
  • [maven-scm-plugin] install version 1.2.1-SNAPSHOT in files
  • [maven-release-plugin] getting ready for the next development iteration
0
source

All Articles