diff --git a/README.md b/README.md index 46205443..c64f2f78 100644 --- a/README.md +++ b/README.md @@ -250,6 +250,12 @@ Then the development branch is set to the next development version. This allows the development branch to continue immediately with a new version and helps avoid any future merge conflicts related to project versioning. Has effect only when there are separate development and production branches. +The `gitflow:release-finish` goal has `mergeDevelopmentVersion` parameter which controls whether the release version or next development version will be merged from release branch into develop branch. +By default the value is `false` which means that the next development version is set on the development branch after the release branch has been merged onto the development branch when finishing the release. +If the value is `true` then the released version from release branch is merged to master branch and then is the next development version set on the release branch and merged into develop branch. +This preserve ability to continue immediately with a new version in the development branch and any future merge conflicts related to project versioning are still avoided. Moreover no release version is committed to develop branch so continuous build and deploy tools can save work on development branch. +Has effect only when there are separate development and production branches and the `commitDevelopmentVersionAtStart` parameter is not set to true. + The `gitflow:release-start` goal has `sameBranchName` parameter which can be used to use the same name for the release branch. The default value is `false`. By itself the default `releaseBranchPrefix` is not a valid branch name. You must change it when setting `sameBranchName` to `true`. Will have no effect if the `branchName` parameter is set. diff --git a/src/main/java/com/amashchenko/maven/plugin/gitflow/GitFlowReleaseFinishMojo.java b/src/main/java/com/amashchenko/maven/plugin/gitflow/GitFlowReleaseFinishMojo.java index 03c684a8..67e2e146 100644 --- a/src/main/java/com/amashchenko/maven/plugin/gitflow/GitFlowReleaseFinishMojo.java +++ b/src/main/java/com/amashchenko/maven/plugin/gitflow/GitFlowReleaseFinishMojo.java @@ -24,7 +24,9 @@ import org.apache.maven.plugin.MojoFailureException; import org.apache.maven.plugins.annotations.Mojo; import org.apache.maven.plugins.annotations.Parameter; +import org.apache.maven.shared.release.versions.VersionParseException; import org.codehaus.plexus.util.StringUtils; +import org.codehaus.plexus.util.cli.CommandLineException; /** * The git flow release finish mojo. @@ -167,6 +169,15 @@ public class GitFlowReleaseFinishMojo extends AbstractGitFlowMojo { @Parameter(property = "skipReleaseMergeProdBranch", defaultValue = "false") private boolean skipReleaseMergeProdBranch = false; + /** + * Whether to merge development or release version to development branch.
+ * Will have no effect if the commitDevelopmentVersionAtStart parameter is set to true. + * + * @since 1.16.1 + */ + @Parameter(property = "mergeDevelopmentVersion", defaultValue = "false") + private boolean mergeDevelopmentVersion; + /** {@inheritDoc} */ @Override public void execute() throws MojoExecutionException, MojoFailureException { @@ -291,6 +302,11 @@ public void execute() throws MojoExecutionException, MojoFailureException { } if (notSameProdDevName()) { + if (!commitDevelopmentVersionAtStart && mergeDevelopmentVersion) { + gitCheckout(releaseBranch); + commitSnapshotVersion(currentVersion); + } + // git checkout develop gitCheckout(gitFlowConfig.getDevelopmentBranch()); @@ -325,34 +341,7 @@ public void execute() throws MojoExecutionException, MojoFailureException { } if (!commitDevelopmentVersionAtStart) { - // get next snapshot version - final String nextSnapshotVersion; - if (!settings.isInteractiveMode() - && StringUtils.isNotBlank(developmentVersion)) { - nextSnapshotVersion = developmentVersion; - } else { - GitFlowVersionInfo versionInfo = new GitFlowVersionInfo( - currentVersion); - if (digitsOnlyDevVersion) { - versionInfo = versionInfo.digitsVersionInfo(); - } - - nextSnapshotVersion = versionInfo - .nextSnapshotVersion(versionDigitToIncrement); - } - - if (StringUtils.isBlank(nextSnapshotVersion)) { - throw new MojoFailureException( - "Next snapshot version is blank."); - } - - // mvn versions:set -DnewVersion=... -DgenerateBackupPoms=false - mvnSetVersions(nextSnapshotVersion); - - messageProperties.put("version", nextSnapshotVersion); - - // git commit -a -m updating for next development version - gitCommit(commitMessages.getReleaseFinishMessage(), messageProperties); + commitSnapshotVersion(currentVersion); } if (installProject) { @@ -379,4 +368,32 @@ public void execute() throws MojoExecutionException, MojoFailureException { throw new MojoFailureException("release-finish", e); } } + + private void commitSnapshotVersion(final String currentVersion) throws MojoFailureException, VersionParseException, CommandLineException { + // get next snapshot version + final String nextSnapshotVersion; + if (!settings.isInteractiveMode() && StringUtils.isNotBlank(developmentVersion)) { + nextSnapshotVersion = developmentVersion; + } else { + GitFlowVersionInfo versionInfo = new GitFlowVersionInfo(currentVersion); + if (digitsOnlyDevVersion) { + versionInfo = versionInfo.digitsVersionInfo(); + } + + nextSnapshotVersion = versionInfo.nextSnapshotVersion(versionDigitToIncrement); + } + + if (StringUtils.isBlank(nextSnapshotVersion)) { + throw new MojoFailureException("Next snapshot version is blank."); + } + + // mvn versions:set -DnewVersion=... -DgenerateBackupPoms=false + mvnSetVersions(nextSnapshotVersion); + + final Map messageProperties = new HashMap<>(); + messageProperties.put("version", nextSnapshotVersion); + + // git commit -a -m updating for next development version + gitCommit(commitMessages.getReleaseFinishMessage(), messageProperties); + } }