Maven 版本:为每个后续版本执行覆盖第一个版本 [英] Maven release:perform overwriting first ever release for every subsequent release

查看:51
本文介绍了Maven 版本:为每个后续版本执行覆盖第一个版本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

更新 我将这个问题标记为关闭,因为似乎没有解决方案 - 插件根本无法正常运行,而且似乎没有人知道为什么.我最终编写了一个小程序来手动复制发布插件的所需行为,使用其他插件,例如 scmversions.如果您想了解我是如何做到这一点的,请随时给我发电子邮件.

<小时>

我最近将我的项目移至 maven.但是,我在发布过程中遇到了问题.

我的发布流程如下:

mvn scm:checkout -DconnectionUrl=scm:svn:https://my-server/svn/my-project/trunk -DcheckoutDirectory=my-projectcd 我的项目mvn --batch-mode 发布:准备mvn 发布:执行

我从 1.0.0-SNAPSHOT 开始,运行上面显示的发布程序.这将我的 repo 更新为以下内容(按新鲜度的升序):

1.0.0-SNAPSHOT1.0.01.0.1-快照

一切都按预期进行,包括更新为指向 1.0.1-SNAPSHOTpom.xml 和名为 my-project-1.0.0 的标签 在我的 SCM 中创建.但是,当我再次运行该过程时,我的存储库中会出现以下内容:

1.0.0-SNAPSHOT1.0.1-快照1.0.01.0.2-快照

也就是说,从不创建 1.0.1 版本,而是将 1.0.1-SNAPSHOT 发布到 1.0.0.请注意,所有其他方面都按预期运行 - pom.xml 现在指向 1.0.2-SNAPSHOT 并且在我的 SCM 中创建了一个名为 my 的标签-project-1.0.1.

实际上,每次我运行发布程序时,快照都会增加,但发布会写入 1.0.0,但从未创建过新发布.例如,再重新运行发布程序 3 次,结果如下:

1.0.0-SNAPSHOT1.0.1-快照1.0.2-快照1.0.3-快照1.0.4-快照1.0.01.0.5-快照

上述预期的行为是:

1.0.0-SNAPSHOT1.0.01.0.1-快照1.0.11.0.2-快照1.0.21.0.3-快照1.0.31.0.4-快照1.0.41.0.5-快照

第一个版本的 pom.xml 如下所示:

<project xmlns="http://maven.apache.org/POM/4.0.0" x mlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"><modelVersion>4.0.0</modelVersion><groupId>com.foo</groupId><artifactId>我的项目</artifactId><包装>罐</包装><version>1.0.0-SNAPSHOT</version><name>我的项目</name><分销管理><存储库><id>我的服务器</id><url>file://\\my-server\repo\</url></repository></distributionManagement><scm><developerConnection>scm:svn:https://my-server/svn/my-project</developerConnection></scm><构建><插件><插件><groupId>org.apache.maven.plugins</groupId><artifactId>maven-release-plugin</artifactId><version>2.4.1</version></插件></plugins></build><存储库><存储库><id>我的服务器</id><url>file://\\my-server\repo\</url></repository></repositories></项目>

下面的一个答案建议我应该创建一个单独的 releasesnapshot 存储库,但我没有.这可能是导致问题的原因吗?

请注意,每当提交代码时,我都使用 Jenkins 自动调用 mvn deploy.然而,这完全符合预期(即将提交的 pom.xml 中指定的任何版本部署到存储库)所以我怀疑这是问题的一部分.

非常感谢您的帮助.

<小时>

更新

检查 mvn release:perform 命令的输出,我看到以下内容:

正在签出项目以执行发布...执行: cmd.exe/X/C "svn --non-interactive checkout https://my-server/svn/my-project/tags/my-project-1.0.2 c:\localrelease\mvn\my-project\目标\结帐"工作目录:c:\localrelease\mvn\my-project\target在目录 c:\localrelease\mvn\my-project\target\checkout\tags\my-project-1.0.0\trunk 中调用执行目标执行目标部署"...

它每次都发布到 1.0.0 是有原因的 - 它检查更新的标签,但在旧的 1.0.0 标签上发布(甚至尽管 1.0.1 标记存在于目标/签出文件夹中).为什么要这样做?

<小时>

更新 2

我已拆分为 2 个单独的存储库(一个用于快照,一个用于目标),但此问题仍然存在.

此外,我在进一步调查 release:perform 的日志时注意到了一些事情:标签 my-project-1.0.1 的结帐包含 的标签1.0.0.同样,标签 1.0.2 的 checkout 包含标签 1.0.01.0.1 等.这是正确的行为吗?>

也许发布过程总是在它检查出的任何东西的标签文件夹中查找并使用它找到的第一个,对于每个发布,它总是1.0.0除了 第一个版本.

这似乎是一个非常奇怪的解释,但这是迄今为止我所看到的唯一一种解释.现在的问题是,我在 pom.xml 中错误地配置了什么导致这种情况发生?

另一个注意事项:在执行发布时,部署目标抱怨 'build.plugins.plugin.version' for org.apache.maven.plugins:maven-xxxx-plugin 丢失. for maven-javadoc-pluginmaven-deploy-pluginmaven-source-plugin.我需要明确添加这些吗?

解决方案

首先是你从错误的版本开始:

  1. 检查最新的代码(当前最新的 pom 指向 1.0.0)
  2. 创建新版本 1.0.1-SNAPSHOT
  3. 更新 pom 以指向 1.0.1-SNAPSHOT 并提交

通常的方法是从 SNAPSHOT 版本开始(也是第一个开发步骤),因为 SNAPSHOT 表明它正在开发中,正在准备发布.

  1. 使用 1.0.0-SNAPSHOT 版本检查最新代码
  2. 将在 SVN 中创建一个标签 1.0.0 并创建新的 pom (maven-release-prepare 描述了详细步骤).
  3. 创建新版本 1.0.1-SNAPSHOT

发布后:perform 将执行以下操作:

签出标记版本 1.0.0 并将部署站点部署(maven-release-perform)

发布周期的下一个调用将从 1.0.1-SNAPSHOT 到 1.0.1 版本和 1.0.2-SNAPSHOT 用于下一个开发周期.

除了上述之外,您应该使用像 Artifactory、Nexus、Archiva 这样的存储库管理器而不是文件存储库.如果 RepoMgmt 有一个单独的存储库用于快照和发布,这可以不时清理快照存储库.您还可以使用文件访问进行设置,这应该以正确的方式完成,如下所示:

<存储库><id>发布</id><url>file:///C:/maven/releases</url></repository><快照存储库><id>快照</id><url>file:///C:/maven/snapshots</url></snapshotRepository><网站><id>站点</id><url>file:///C:/maven/sites/${project.groupId}/${project.artifactId}/${project.version}</url></网站></distributionManagement>

此外,如果您制作单独的 SNAPSHOT 和发布存储库,则元数据文件在发布存储库和 SNAPSHOT 存储库中看起来会有所不同.

默认的发布周期是从 SNAPSHOT 到下一个 SNAPSHOT,如下所示:

<代码>1.循环1.0.2-快照1.0.21.0.3-快照2. 循环1.0.3-快照1.0.31.0.4-快照3. 循环1.0.4-快照1.0.41.0.5-快照等等.

Update I am flagging this question to be closed as there seems to be no solution - the plugin is simply not behaving as it should and no-one seems to know why. I have ended up writing a small program to manually replicate the desired behaviour of the release plugin myself, using other plugins such as scm and versions. If you would like information on how I did this feel free to email me.


I have recently moved my project to maven. However, I am having issues with the release process.

My release procedure is as follows:

mvn scm:checkout -DconnectionUrl=scm:svn:https://my-server/svn/my-project/trunk -DcheckoutDirectory=my-project
cd my-project
mvn --batch-mode release:prepare
mvn release:perform

I start on 1.0.0-SNAPSHOT, I run the release procedure shown above. This updates my repo to the following (in ascending order of newness):

1.0.0-SNAPSHOT
1.0.0
1.0.1-SNAPSHOT

Everything occurs as expected, including the pom.xml updated to point to 1.0.1-SNAPSHOT and a tag called my-project-1.0.0 created in my SCM. However, when I run the procedure again, the following appears in my repo:

1.0.0-SNAPSHOT
1.0.1-SNAPSHOT
1.0.0
1.0.2-SNAPSHOT

That is, release 1.0.1 is never created, and instead 1.0.1-SNAPSHOT is released to 1.0.0. Note that every other aspect runs as expected - the pom.xml now points to 1.0.2-SNAPSHOT and a tag is created in my SCM with the name my-project-1.0.1.

In fact, every time I run the release procedure, the SNAPSHOT increases but the release is written to 1.0.0 with a new release never created. For example, re-running the release procedure 3 further times results in the following:

1.0.0-SNAPSHOT
1.0.1-SNAPSHOT
1.0.2-SNAPSHOT
1.0.3-SNAPSHOT
1.0.4-SNAPSHOT
1.0.0
1.0.5-SNAPSHOT

The expected behaviour for the above is:

1.0.0-SNAPSHOT
1.0.0
1.0.1-SNAPSHOT
1.0.1
1.0.2-SNAPSHOT
1.0.2
1.0.3-SNAPSHOT
1.0.3
1.0.4-SNAPSHOT
1.0.4
1.0.5-SNAPSHOT

The pom.xml for the very first version is shown below:

<project xmlns="http://maven.apache.org/POM/4.0.0" x mlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">

<modelVersion>4.0.0</modelVersion>
<groupId>com.foo</groupId>
<artifactId>my-project</artifactId>
<packaging>jar</packaging>
<version>1.0.0-SNAPSHOT</version>
<name>my-project</name>

<distributionManagement>
    <repository>
        <id>my-server</id>
        <url>file://\\my-server\repo\</url>
    </repository>
</distributionManagement>

<scm>
    <developerConnection>scm:svn:https://my-server/svn/my-project</developerConnection>
</scm>

<build>
    <plugins>

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-release-plugin</artifactId>
            <version>2.4.1</version>
        </plugin>       

    </plugins>


</build>

<repositories>
    <repository>
        <id>my-server</id>
        <url>file://\\my-server\repo\</url>
    </repository>
</repositories>

</project>

One of the answers below suggests I should create a separate release and snapshot repo, which I have not. Could this be causing the issue?

Note that I am using Jenkins to automatically invoke mvn deploy whenever code is committed. However this is acting exactly as expected (i.e. deploying whichever version is specified in the committed pom.xml to the repo) so I doubt this is part of the problem.

Many thanks for any assistance.


Update

Examining the output from the mvn release:perform command I see the following:

Checking out the project to perform the release ...
Executing: cmd.exe /X /C "svn --non-interactive checkout https://my-server/svn/my-project/tags/my-project-1.0.2 c:\localrelease\mvn\my-project\target\checkout"
Working directory: c:\localrelease\mvn\my-project\target
Invoking perform goals in directory c:\localrelease\mvn\my-project\target\checkout\tags\my-project-1.0.0\trunk
Executing goals 'deploy'...

And there is the reason it is releasing to 1.0.0 every time - it checks out the updated tag, but releases on the old 1.0.0 tag (even though the 1.0.1 tag IS present in the target/checkout folder). Why is it doing this?


Update 2

I have split to 2 separate repositories (one for snapshot and one for target) and this issue still occurs.

Also, something I have noticed upon investigating log for release:perform further: The checkout for tag my-project-1.0.1 contains the tag for 1.0.0. Similarly, the checkout for tag 1.0.2 contains the tags 1.0.0 and 1.0.1, etc. Is this correct behaviour?

Perhaps the release process is always looking in the tags folder of whatever it checks out and uses the first one it finds, which will always be 1.0.0 for every releases except the first release.

This seems like a very strange explanation but it is the only one I have so far for the behaviour I see. The question now is, what have I configured in my pom.xml incorrectly to cause this to happen?

Another note: when performing the release the deploy goal complains that 'build.plugins.plugin.version' for org.apache.maven.plugins:maven-xxxx-plugin is missing. for maven-javadoc-plugin, maven-deploy-plugin and maven-source-plugin. Do I need to explicitly add these?

解决方案

The first things is that you are starting with the wrong version:

  1. checks out the latest code (with the latest pom currently pointing to 1.0.0)
  2. creates a new version 1.0.1-SNAPSHOT
  3. updates the pom to point to 1.0.1-SNAPSHOT and commits it

The usual way is to start with a SNAPSHOT version (also the first development steps), cause SNAPSHOT indicates it's under development on a way to a release.

  1. checkout latest code with version 1.0.0-SNAPSHOT
  2. will create a tag 1.0.0 in SVN and create new pom's (maven-release-prepare describes the detailed steps).
  3. creates a new version 1.0.1-SNAPSHOT

afterwards the release:perform will do the following:

checkout the tagged version 1.0.0 and will deploy site-deploy (maven-release-perform)

And the next call of the release cycle will go from 1.0.1-SNAPSHOT to 1.0.1 release and 1.0.2-SNAPSHOT for next development cycle.

Apart from the above you should use a repository manager like Artifactory, Nexus, Archiva instead of a file repository. In case if a RepoMgmt you have a separate repository for SNAPSHOT's and for releases which give the possibility to clean up the SNAPSHOT repository from time to time. You can also make a setup with file access which should be done in the correct way like the following:

<distributionManagement>
    <repository>
      <id>releases</id>
      <url>file:///C:/maven/releases</url>
    </repository>
    <snapshotRepository>
      <id>snapshots</id>
      <url>file:///C:/maven/snapshots</url>
    </snapshotRepository>
    <site>
      <id>site</id>
      <url>file:///C:/maven/sites/${project.groupId}/${project.artifactId}/${project.version}</url>
    </site>
</distributionManagement>

Furthermore if you make separate SNAPSHOT and release repository the metadata file will be looking different in release repository and SNAPSHOT repository.

The default release cycle is going from SNAPSHOT over a release to next SNAPSHOT like this:

1. Cycle
1.0.2-SNAPSHOT
1.0.2
1.0.3-SNAPSHOT

2. Cycle
1.0.3-SNAPSHOT
1.0.3
1.0.4-SNAPSHOT

3. Cycle
1.0.4-SNAPSHOT
1.0.4
1.0.5-SNAPSHOT

and so forth.

这篇关于Maven 版本:为每个后续版本执行覆盖第一个版本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆