Maven版本,subversion分支和本地存储库

时间:2022-09-13 23:56:36

Imagine following scenario:

想象一下以下场景:

We have a lot of parallel development going on in several svn branches. Some projects are unbranched and some are branched. There is a lot of interdependency. We also have a local repository (so none of the developer downloads packages directly, we use our own maven repository).

我们在几个svn分支中进行了大量的并行开发。有些项目是不分支的,有些是分支的。有很多相互依赖。我们还有一个本地存储库(因此没有开发人员直接下载软件包,我们使用自己的maven存储库)。

The problem is with maven we have to specify versions in all the pom files. The artifacts with the version is stored in our local repository. While working with several branches, we will override same version (in the pom file) of artifacts with the artifacts from another branch.

问题是maven我们必须在所有pom文件中指定版本。具有该版本的工件存储在我们的本地存储库中。在处理多个分支时,我们将使用来自另一个分支的工件覆盖工件的相同版本(在pom文件中)。

If I use the version number in the pom file also to include some branch info, the problem arises for the unbranched modules which depend on many branched modules.

如果我使用pom文件中的版本号也包含一些分支信息,那么依赖于许多分支模块的非分支模块就会出现问题。

Is there any standard solution / policy to cope up with this issue ?

是否有任何标准的解决方案/政策来应对这个问题?

To create a separate repository for each branch is a solution, but looking at the number of branches we may have, it is a bit expensive.

为每个分支创建一个单独的存储库是一个解决方案,但是看看我们可能拥有的分支数量,它有点贵。

3 个解决方案

#1


Could you use the classifier feature for your artifact?

你可以为你的工件使用分类器功能吗?

I don't think it's SOP to use classifier for this, but it should work. I believe the intent of classifier is to create different versions of an artifact based upon region specific filters, JDK versions, etc. But this seems to be a very project/environment specific thing so I think it would be just fine to hijack it for this.

我不认为这是使用分类器的SOP,但它应该工作。我相信分类器的意图是根据区域特定的过滤器,JDK版本等创建不同版本的工件。但这似乎是一个非常项目/环境的事情,所以我认为劫持它就好了。

If you were to specify your artifacts like this:

如果您要指定这样的工件:

<artifactId>artifact-a</artifactId>
<groupId>com.mygroup</groupId>
<version>1.1-SNAPSHOT</version>
<classifier>BRANCH-Q</classifier>

In your repository you would get:

在您的存储库中,您将获得:

artifact-a-1.1-SNAPSHOT-BRANCH-Q.jar

Then you could specify artifacts in dependencies using the classifier to get the right one.

然后,您可以使用分类器指定依赖关系中的工件以获取正确的工件。

#2


I think your approach adding the branch name to the version is the correct one.

我认为你在版本中添加分支名称的方法是正确的。

However you should try to avoid having unbranched artifacts depending on branched versions.

但是,您应该尝试避免根据分支版本使用不分支的工件。

Consider you have A in trunk which depends on a version of B in a branch called DEV.

考虑你在主干中有一个A依赖于一个名为DEV的分支中的B版本。

In this case I would argue that either A should depend on a released version of B in trunk or else should be in the DEV branch itself.

在这种情况下,我认为A应该依赖于主干中B的发布版本,否则应该在DEV分支本身。

Hope that made sense...

希望有意义......

#3


I don't know of a standard approach to this. Generally it's easiest to differentiate branches by appending something different to the version number, or possibly the artifactID.

我不知道对此采用标准方法。通常,通过附加与版本号不同的东西或者可能是artifactID来区分分支是最容易的。

You can also use a numbering scheme to differentiate branches. For example if the trunk is version 2.0 (next major release), then the branch could be 1.1 (maintenance release for previous release).

您还可以使用编号方案来区分分支。例如,如果主干是版本2.0(下一个主要版本),则分支可以是1.1(先前版本的维护版本)。

I'm not sure what you mean by "our local repository". If you mean a shared internal team/company repository, then by all means you want to avoid version collisions across different branches, otherwise you will get very strange build problems with different artifacts having the same name/version.

我不确定“我们的本地存储库”是什么意思。如果您的意思是共享的内部团队/公司存储库,那么无论如何您都希望避免跨不同分支的版本冲突,否则您将会遇到具有相同名称/版本的不同工件的非常奇怪的构建问题。

If developers are working the branches ONLY on their local repositories and those branched artifacts are not getting added to some shared repository (via some CI server, for example) then you should generally be ok.

如果开发人员仅在其本地存储库上运行分支,并且这些分支工件不会被添加到某个共享存储库(例如,通过某个CI服务器),那么您通常应该没问题。

You also have to be careful about branched projects depending on shared artifacts.

您还必须注意分支项目,具体取决于共享工件。

Suppose you have A (trunk) and B (branch) both depending on C. If you make a change in C to support changes in B, then A will be affected. You have to branch B in this situation, or just be very careful.

假设您有A(主干)和B(分支)两者都取决于C.如果您在C中进行更改以支持B中的更改,则A将受到影响。在这种情况下你必须分支B,或者只是非常小心。

#1


Could you use the classifier feature for your artifact?

你可以为你的工件使用分类器功能吗?

I don't think it's SOP to use classifier for this, but it should work. I believe the intent of classifier is to create different versions of an artifact based upon region specific filters, JDK versions, etc. But this seems to be a very project/environment specific thing so I think it would be just fine to hijack it for this.

我不认为这是使用分类器的SOP,但它应该工作。我相信分类器的意图是根据区域特定的过滤器,JDK版本等创建不同版本的工件。但这似乎是一个非常项目/环境的事情,所以我认为劫持它就好了。

If you were to specify your artifacts like this:

如果您要指定这样的工件:

<artifactId>artifact-a</artifactId>
<groupId>com.mygroup</groupId>
<version>1.1-SNAPSHOT</version>
<classifier>BRANCH-Q</classifier>

In your repository you would get:

在您的存储库中,您将获得:

artifact-a-1.1-SNAPSHOT-BRANCH-Q.jar

Then you could specify artifacts in dependencies using the classifier to get the right one.

然后,您可以使用分类器指定依赖关系中的工件以获取正确的工件。

#2


I think your approach adding the branch name to the version is the correct one.

我认为你在版本中添加分支名称的方法是正确的。

However you should try to avoid having unbranched artifacts depending on branched versions.

但是,您应该尝试避免根据分支版本使用不分支的工件。

Consider you have A in trunk which depends on a version of B in a branch called DEV.

考虑你在主干中有一个A依赖于一个名为DEV的分支中的B版本。

In this case I would argue that either A should depend on a released version of B in trunk or else should be in the DEV branch itself.

在这种情况下,我认为A应该依赖于主干中B的发布版本,否则应该在DEV分支本身。

Hope that made sense...

希望有意义......

#3


I don't know of a standard approach to this. Generally it's easiest to differentiate branches by appending something different to the version number, or possibly the artifactID.

我不知道对此采用标准方法。通常,通过附加与版本号不同的东西或者可能是artifactID来区分分支是最容易的。

You can also use a numbering scheme to differentiate branches. For example if the trunk is version 2.0 (next major release), then the branch could be 1.1 (maintenance release for previous release).

您还可以使用编号方案来区分分支。例如,如果主干是版本2.0(下一个主要版本),则分支可以是1.1(先前版本的维护版本)。

I'm not sure what you mean by "our local repository". If you mean a shared internal team/company repository, then by all means you want to avoid version collisions across different branches, otherwise you will get very strange build problems with different artifacts having the same name/version.

我不确定“我们的本地存储库”是什么意思。如果您的意思是共享的内部团队/公司存储库,那么无论如何您都希望避免跨不同分支的版本冲突,否则您将会遇到具有相同名称/版本的不同工件的非常奇怪的构建问题。

If developers are working the branches ONLY on their local repositories and those branched artifacts are not getting added to some shared repository (via some CI server, for example) then you should generally be ok.

如果开发人员仅在其本地存储库上运行分支,并且这些分支工件不会被添加到某个共享存储库(例如,通过某个CI服务器),那么您通常应该没问题。

You also have to be careful about branched projects depending on shared artifacts.

您还必须注意分支项目,具体取决于共享工件。

Suppose you have A (trunk) and B (branch) both depending on C. If you make a change in C to support changes in B, then A will be affected. You have to branch B in this situation, or just be very careful.

假设您有A(主干)和B(分支)两者都取决于C.如果您在C中进行更改以支持B中的更改,则A将受到影响。在这种情况下你必须分支B,或者只是非常小心。