如何使用 Maven 从 SVN 标签创建分支?

发布于 2024-09-10 07:04:58 字数 3754 浏览 2 评论 0原文

假设我已在 $SVNROOT/project/tags/1.0 下标记了我们项目的发布版本。现在假设我需要从该标记创建一个分支,将其标记为 SNAPSHOT,并更新 scm 配置。

我尝试使用 release:prepare 目标:

$ svn co $SVNROOT/project/tags/1.0 project-1.0
$ cd project-1.0
$ mvn release:branch -DbranchName=project-1.0.X -DupdateBranchVersions=true -DupdateWorkingCopyVersions=false

但这失败了,并显示一条错误消息,警告我没有对 $SVNROOT/project/tags/1.0 项目的提交权限 - 1.0 路径(这是完全正确的——我们不允许提交到标签中)。

我在这里做错了什么,为什么 Maven 试图在标签中提交一些东西?

更新

只是为了澄清:我从我签出标签的目录中运行它。我收到的确切错误如下:

[INFO] Executing: /bin/sh -c cd xxx && svn --non-interactive commit --file /tmp/maven-scm-28755080.commit --targets /tmp/maven-scm-535803351230252749-targets
[INFO] Working directory: xxx
org.apache.maven.shared.release.scm.ReleaseScmCommandException: Unable to commit files
Provider message:
The svn command failed.
Command output:
svn: Commit failed (details follow):
svn: 'pre-commit' hook failed with error output:
you do not have the rights to access this file: xxx/tags/xxx. 


        at org.apache.maven.shared.release.phase.ScmCommitPhase.checkin(ScmCommitPhase.java:133)
        at org.apache.maven.shared.release.phase.ScmCommitPhase.execute(ScmCommitPhase.java:109)
        at org.apache.maven.shared.release.DefaultReleaseManager.branch(DefaultReleaseManager.java:379)
        at org.apache.maven.shared.release.DefaultReleaseManager.branch(DefaultReleaseManager.java:350)
        at org.apache.maven.plugins.release.BranchReleaseMojo.execute(BranchReleaseMojo.java:133)
        at org.apache.maven.plugin.DefaultPluginManager.executeMojo(DefaultPluginManager.java:490)
        at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoals(DefaultLifecycleExecutor.java:694)
        at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeStandaloneGoal(DefaultLifecycleExecutor.java:569)
        at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoal(DefaultLifecycleExecutor.java:539)
        at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoalAndHandleFailures(DefaultLifecycleExecutor.java:387)
        at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeTaskSegments(DefaultLifecycleExecutor.java:284)
        at org.apache.maven.lifecycle.DefaultLifecycleExecutor.execute(DefaultLifecycleExecutor.java:180)
        at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:328)
        at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:138)
        at org.apache.maven.cli.MavenCli.main(MavenCli.java:362)
        at org.apache.maven.cli.compat.CompatibleMain.main(CompatibleMain.java:60)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:616)
        at org.codehaus.classworlds.Launcher.launchEnhanced(Launcher.java:315)
        at org.codehaus.classworlds.Launcher.launch(Launcher.java:255)
        at org.codehaus.classworlds.Launcher.mainWithExitCode(Launcher.java:430)
        at org.codehaus.classworlds.Launcher.main(Launcher.java:375)
[INFO] ------------------------------------------------------------------------
[ERROR] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Unable to commit files
Provider message:
The svn command failed.
Command output:
svn: Commit failed (details follow):
svn: 'pre-commit' hook failed with error output:
you do not have the rights to access this file: xxx/tags/xxx. 

Suppose I have tagged the release version of our project under $SVNROOT/project/tags/1.0. Suppose now that I need to create a branch from that tag, mark it as being a SNAPSHOT, and update the scm configuration.

I tried with the release:prepare goal thus:

$ svn co $SVNROOT/project/tags/1.0 project-1.0
$ cd project-1.0
$ mvn release:branch -DbranchName=project-1.0.X -DupdateBranchVersions=true -DupdateWorkingCopyVersions=false

But this fails, with an error message warning me that I don't have commit rights into the $SVNROOT/project/tags/1.0 project-1.0 path (which is perfectly true---we don't allow commits into tags).

What am I doing wrong here, and why was Maven trying to commit something in the tag?

Update

Just to clarify: I am running this from the directory into which I've checked out the tag. The exact error I'm getting is the following:

[INFO] Executing: /bin/sh -c cd xxx && svn --non-interactive commit --file /tmp/maven-scm-28755080.commit --targets /tmp/maven-scm-535803351230252749-targets
[INFO] Working directory: xxx
org.apache.maven.shared.release.scm.ReleaseScmCommandException: Unable to commit files
Provider message:
The svn command failed.
Command output:
svn: Commit failed (details follow):
svn: 'pre-commit' hook failed with error output:
you do not have the rights to access this file: xxx/tags/xxx. 


        at org.apache.maven.shared.release.phase.ScmCommitPhase.checkin(ScmCommitPhase.java:133)
        at org.apache.maven.shared.release.phase.ScmCommitPhase.execute(ScmCommitPhase.java:109)
        at org.apache.maven.shared.release.DefaultReleaseManager.branch(DefaultReleaseManager.java:379)
        at org.apache.maven.shared.release.DefaultReleaseManager.branch(DefaultReleaseManager.java:350)
        at org.apache.maven.plugins.release.BranchReleaseMojo.execute(BranchReleaseMojo.java:133)
        at org.apache.maven.plugin.DefaultPluginManager.executeMojo(DefaultPluginManager.java:490)
        at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoals(DefaultLifecycleExecutor.java:694)
        at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeStandaloneGoal(DefaultLifecycleExecutor.java:569)
        at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoal(DefaultLifecycleExecutor.java:539)
        at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoalAndHandleFailures(DefaultLifecycleExecutor.java:387)
        at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeTaskSegments(DefaultLifecycleExecutor.java:284)
        at org.apache.maven.lifecycle.DefaultLifecycleExecutor.execute(DefaultLifecycleExecutor.java:180)
        at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:328)
        at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:138)
        at org.apache.maven.cli.MavenCli.main(MavenCli.java:362)
        at org.apache.maven.cli.compat.CompatibleMain.main(CompatibleMain.java:60)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:616)
        at org.codehaus.classworlds.Launcher.launchEnhanced(Launcher.java:315)
        at org.codehaus.classworlds.Launcher.launch(Launcher.java:255)
        at org.codehaus.classworlds.Launcher.mainWithExitCode(Launcher.java:430)
        at org.codehaus.classworlds.Launcher.main(Launcher.java:375)
[INFO] ------------------------------------------------------------------------
[ERROR] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Unable to commit files
Provider message:
The svn command failed.
Command output:
svn: Commit failed (details follow):
svn: 'pre-commit' hook failed with error output:
you do not have the rights to access this file: xxx/tags/xxx. 

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

凤舞天涯 2024-09-17 07:04:58

您在哪里执行该命令 mvn release:branch< /代码>

正如在此线程中提到的

插件 doco 指定的是release:branch 目标应该是
使用您想要分支的 revision/tag 从结帐位置调用
来自
。 (即tags/)。

我使用以下命令行从现有标记位置 (tags/myapp-1.3) 创建维护分支 (branches/myapp-1.3.1):< /p>

mvn release:branch -DbranchName=myapp-1.3.1 -DupdateBranchVersions=true
-DupdateWorkingCopyVersions=false

-DupdateBranchVersions 标志与 pom.xml 中的版本相关,而不是 scm 版本。
如果为 false,它将保留与标记版本相同的版本;
如果为 true,它将提示输入版本,默认为标记版本的快照,这可能是也可能不是您想要的。

另请参阅此帖子

首先,您需要从标记中签出工作副本
如果标签是由发布插件创建的,则起始 scm url 应该是正确的,并指向该标签。

然后使用插件创建分支并将工作副本切换到分支。

另一种方法是手动:

  • 从标记复制到新分支
  • 将工作副本切换到新分支(或从新分支检出工作副本)
  • 更新 pom 以使用新分支的 url - 将更新提交到 pom

Where did you execute that command mvn release:branch?

As mentioned in this thread:

What the plugin doco does specify is that the release:branch goal should be
invoked from a checkout location with the revision/tag you want to branch
from
. (i.e. tags/<my_release_version>).

I used the following commandline to create a maintenance branch (branches/myapp-1.3.1) from an existing tag location (tags/myapp-1.3):

mvn release:branch -DbranchName=myapp-1.3.1 -DupdateBranchVersions=true
-DupdateWorkingCopyVersions=false

The -DupdateBranchVersions flag pertains to the versions in the pom.xml - not the scm versions.
If false, it will retain the same version as the tagged release;
if true, it will prompt for a version, defaulting to a snapshot of the tagged release, which may or may not be what you want.

See also this thread:

First you need to start with a working copy checked out from the Tag.
If the tag was created by the release plugin, the starting scm url should be correct, and point back to the tag.

Then use the plugin to crate the branch and switch the working copy to the branch.

An alternative is to manually:

  • copy from the tag to a new branch
  • switch the working copy to the new branch (or check out a working copy from the new branch)
  • update the pom to use the new branch's url- commit the update to the pom
旧情别恋 2024-09-17 07:04:58
mvn release:branch
   -DbranchName=${project.artifactId}_${project.version} 
   -Dusername=${username} 
   -Dpassword=${passwd} 
   -DupdateBranchVersions=true 
   -DupdateVersionsToSnapshot=true 
   -DremoteTagging=false 
   -DsuppressCommitBeforeBranch=true 
   -DupdateWorkingCopyVersions=false

-DautoVersionSubmodules=true

运行时,Maven 将提示要在分支中使用的版本。我提供了 1.5.0-azuresupport-SNAPSHOT。由于 autoVersionSubmodules 设置为 true,Maven Release 将自动为所有子模块使用此版本,因此也会将所有内部项目依赖项更新为该版本。

-DsuppressCommitBeforeBranch=true

默认情况下, Maven Releases 创建对当前工作副本的中间提交。我不确定原因,但我认为这是因为某些 VCS 不支持修改后的工作副本的分支/标记。此参数确保不会对工作副本进行任何中间提交。

-DremoteTagging=false

使用 SVN,默认情况下会远程创建标签。如果要省略中间提交,则必须将其设置为 false。

-DupdateBranchVersions=true

-DupdateWorkingCopyVersions=false

分支时,您可以为当前工作副本或新分支或两者定义新版本。按照此处的设置,工作副本将被保留,插件将要求分支的新版本。

这里解释了所有 -D 参数
http://startbigthinksmall.wordpress。 com/2011/11/29/create-branches-with-maven-release-plugin-svn/

mvn release:branch
   -DbranchName=${project.artifactId}_${project.version} 
   -Dusername=${username} 
   -Dpassword=${passwd} 
   -DupdateBranchVersions=true 
   -DupdateVersionsToSnapshot=true 
   -DremoteTagging=false 
   -DsuppressCommitBeforeBranch=true 
   -DupdateWorkingCopyVersions=false

-DautoVersionSubmodules=true

When ran, Maven will prompt for the version to be used in the branch. I provided 1.5.0-azuresupport-SNAPSHOT. Since autoVersionSubmodules is set to true, Maven Release will automatically use this versions for all submodules and hence also update all inner-project dependencies to that version.

-DsuppressCommitBeforeBranch=true

By default, Maven Releases creates intermediate commits to the current working copy. I’m not sure of the reason, but I think it was because some VCS do not support branching/tagging of modified working copies. This parameter makes sure, no intermediate commits are made to the working copy.

-DremoteTagging=false

With SVN, by default, tags are created remotely. If you want to ommit intermediate commits, this must be set to false.

-DupdateBranchVersions=true

-DupdateWorkingCopyVersions=false

When branching, you can either define new versions for the current working copy, or the new branch, or both. As set here, the working copy will be left alone, and the plugin will ask for a new version for the branch.

here you have all the -D arguments explained
http://startbigthinksmall.wordpress.com/2011/11/29/create-branches-with-maven-release-plugin-svn/

够运 2024-09-17 07:04:58

您正在运行的命令看起来不错,并严格遵循 创建分支

默认情况下,新分支中的POM
保持与本地相同的版本
工作副本,本地 POM 是
增加到下一个修订版。如果
您想更新新版本
分支而不是在工作副本中,
运行:

mvn 版本:branch -DbranchName=my-branch -DupdateBranchVersions=true -DupdateWorkingCopyVersions=false

注意:如果您愿意,这会很有用
从标签创建分支

但是,它似乎是一个失败并抱怨的“预提交”钩子。所以我想知道:

  • 你在这个钩子中做什么
  • 如果你暂时禁用这个钩子会发生什么

The commands you're running looks OK and strictly follow the example given in Create a Branch:

By default, the POM in the new branch
keeps the same version as the local
working copy, and the local POM is
incremented to the next revision. If
you want to update versions in the new
branch and not in the working copy,
run:

mvn release:branch -DbranchName=my-branch -DupdateBranchVersions=true -DupdateWorkingCopyVersions=false

Note: This can be useful if you want
to create a branch from a tag

However, it seems that it's a 'pre-commit' hook that is failing and complaining. So I wonder:

  • what you're doing in this hook
  • what happens if you disable this hook temporarily
倚栏听风 2024-09-17 07:04:58

实际问题是 release:branch 目标提交到标签,这是一个 不合理的错误。没有解决方法。您的预提交挂钩可能会失败,因为它的设计(可能是正确的)是为了防止在标记目录内提交。

The actual problem is that the release:branch goal commits to tags, which is an unconscionable bug. There is no workaround. Your pre-commit hook is likely failing because it is designed--probably correctly--to prevent commits inside a tag directory.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文