简体   繁体   English

Maven依赖管理

[英]Maven dependency management

Our project has a dependency like 我们的项目有依赖性

  <dependency>
    <groupId>apollo.components.cots</groupId>
    <artifactId>cots-wfs</artifactId>
  </dependency>

And as far as I understand, maven2 will get the latest artifact for cots-wfs, say <version>2.3-20101111.000000-13</version> 据我所知,maven2将获得cots-wfs的最新工件,比如<version> 2.3-20101111.000000-13 </ version>

The problem is, when we branch the project, the dependency stays the same, and when other developers release a new cots-wfs say <version>2.3-20101222.000000-13</version> which is not backward compatible, the build is broken. 问题是,当我们分支项目时,依赖关系保持不变,当其他开发人员发布新的cots-wfs说<version> 2.3-20101222.000000-13 </ version>时,它不向后兼容,构建就会被破坏。

I am trying to avoid merging the code into the branch, which is painful. 我试图避免将代码合并到分支中,这很痛苦。

So what do I need to do to "freeze" all the dependencies when I branch the project ? 那么当我分支项目时,我需要做什么来“冻结”所有依赖项? Is there any easy way to do this? 有没有简单的方法来做到这一点?

And as far as I understand, maven2 will get the latest artifact for cots-wfs, say <version>2.3-20101111.000000-13</version> 据我所知,maven2将获得<version>2.3-20101111.000000-13</version> -wfs的最新工件,比如<version>2.3-20101111.000000-13</version>

It looks like you are using a SNAPSHOT dependency for cots-wfs ( 2.3-SNAPSHOT ), probably declared in the dependencyManagement section. 看起来你正在对cots-wfs( 2.3-SNAPSHOT )使用SNAPSHOT依赖,可能在dependencyManagement部分中声明了。

The problem is, when we branch the project, the dependency stays the same, and when other developers release a new cots-wfs (...) which is not backward compatible, the build is broken. 问题是,当我们分支项目时,依赖性保持不变,当其他开发人员发布一个不向后兼容的新cots-wfs(...)时,构建就会被破坏。

Indeed, which is why you should simply not branch an artifact with SNAPSHOT dependencies, the build of released artifacts should be reproducible, for ever, and using SNAPSHOT dependencies defeats this. 实际上,这就是为什么你不应该只使用SNAPSHOT依赖关系来分支一个工件的原因,所发布的工件的构建应该是可重现的,并且使用SNAPSHOT依赖关系会失败。 The maven release plugin actually forbids releasing a POM having SNAPSHOT dependencies. maven发布插件实际上禁止释放具有SNAPSHOT依赖性的POM。

It is however possible to "lock" SNAPSHOT dependencies using versions:lock-snapshots or, even better, to use the corresponding released version using versions:use-releases . 但是,可以使用versions:lock-snapshots来锁定SNAPSHOT依赖项versions:lock-snapshots或者更好的是,使用versions:use-releases使用相应的已发布版本。 This is actually the way to go. 这实际上是要走的路。

By the way, the Maven Release Plugin might help to automate the whole process. 顺便说一句, Maven Release Plugin可能有助于整个过程的自动化。

When you branch means in a sense you are creating a new version of it. 当你在某种意义上分支意味着你正在创建它的新版本。 Promoting the version number should solve it. 提升版本号应解决它。

Yeah just add the version tag to the dependency. 是的只是将版本标记添加到依赖项。 If your unsure what the current version number is than run "mvn help:effective-pom" to see the pom with all current version numbers. 如果您不确定当前版本号是什么,请运行“mvn help:effective-pom”来查看包含所有当前版本号的pom。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM