使用maven-release-plugin:branch从tag(git)创建分支失败

时间:2018-01-12 17:19:11

标签: git svn maven-release-plugin

我们正在尝试将一个简单的maven项目从svn迁移到git。我们正在使用maven-release-plugin,工作流程(目前)就像这样:

在happy时使用trunk创建一个发行版本并用以下内容标记它:

trunk -> 2018.02.01-SNAPSHOT

release:prepare release:perform ...

tag -> 2018.02.01
trunk -> 2018.03.01-SNAPSHOT

对于修补,我们从标记创建一个分支:

git checkout 2018.02.01
mvn -B release:branch -DbranchName=release/2018.02 -DupdateBranchVersions=true -DupdateWorkingCopyVersions=false
branch -> 2018.02.02-SNAPSHOT

这在SVN上工作正常,但在git上我们得到以下错误:

[INFO] Scanning for projects...
[INFO]                                                                         
[INFO] ------------------------------------------------------------------------
[INFO] Building my-project 2018.02.01
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] --- maven-release-plugin:2.5.3:branch (default-cli) @ my-project ---
[INFO] Verifying that there are no local modifications...
[INFO]   ignoring changes on: **/pom.xml.releaseBackup, **/pom.xml.next, **/pom.xml.tag, **/pom.xml.branch, **/release.properties, **/pom.xml.backup
[INFO] Executing: /bin/sh -c cd /home/hfm/git/my-project && git rev-parse --show-toplevel
[INFO] Working directory: /home/hfm/git/my-project
[INFO] Executing: /bin/sh -c cd /home/hfm/git/my-project && git status --porcelain .
[INFO] Working directory: /home/hfm/git/my-project
[INFO] Transforming 'my-project'...
[INFO] Checking in modified POMs...
[INFO] Executing: /bin/sh -c cd /home/hfm/git/my-project && git add -- pom.xml
[INFO] Working directory: /home/hfm/git/my-project
[INFO] Executing: /bin/sh -c cd /home/hfm/git/my-project && git rev-parse --show-toplevel
[INFO] Working directory: /home/hfm/git/my-project
[INFO] Executing: /bin/sh -c cd /home/hfm/git/my-project && git status --porcelain .
[INFO] Working directory: /home/hfm/git/my-project
[WARNING] Ignoring unrecognized line: ?? pom.xml.releaseBackup
[INFO] Executing: /bin/sh -c cd /home/hfm/git/my-project && git commit --verbose -F /tmp/maven-scm-112348369.commit pom.xml
[INFO] Working directory: /home/hfm/git/my-project
[INFO] Executing: /bin/sh -c cd /home/hfm/git/my-project && git symbolic-ref HEAD
[INFO] Working directory: /home/hfm/git/my-project
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.086 s
[INFO] Finished at: 2018-01-12T18:13:45+01:00
[INFO] Final Memory: 11M/184M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-release-plugin:2.5.3:branch (default-cli) on project my-project: An error is occurred in the checkin process: Exception while executing SCM command. Detecting the current branch failed: fatal: ref HEAD is not a symbolic ref -> [Help 1]
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException

我理解错误消息fatal: ref HEAD is not a symbolic ref。这是因为我以分离模式签出了一个标签。但是如果我结帐到一个新的分支,那么我将获得2个分支(一个是我手动创建的,另一个是release:branch目标创建的。)

问题是,我们是否以错误的方式使用maven发布插件?或者它不打算以这种方式与git一起使用吗?

1 个答案:

答案 0 :(得分:1)

我们决定停止使用maven-release-plugin,而是在build-helper-maven-pluginversions-maven-plugin的帮助下做同样的事情。步骤看起来像这样:

git checkout -b release/2018.02 2018.02.01

mvn build-helper:parse-version versions:set -DnewVersion=${parsedVersion.majorVersion}.${formattedVersion.minorVersion}.${formattedVersion.nextIncrementalVersion}-SNAPSHOT

mvn versions:commit

git commit -am "Bumped dev version for release branch."

git push