在Maven中,模块是否受到存储库updatePolicy的影响? [英] In Maven, do modules get effected by the repository's updatePolicy?

查看:130
本文介绍了在Maven中,模块是否受到存储库updatePolicy的影响?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这就像我提出的其他问题,但不是依赖,这是关于模块的。让我给出一个场景。你有一个多模块项目和一个部署项目的持续集成服务器。这将部署到存储库,您的本地 settings.xml 始终。现在假设您在CI部署项目后立即运行 mvn compile

This is just like this other question I asked, but instead of dependencies, this is about modules. Let me give a scenario. You've got a multi-module project and a continuous integration server that deploys the project. This deploys to a repository that your local settings.xml has an updatePolicy of always. Now imagine you run mvn compile right after the CI deploys the project.

您最终是否会针对远程服务器的模块或本地模块进行编译?

Will you end up compiling against the remote server's modules, or your local modules?

换句话说,存储库的 updatePolicy 有任何影响吗?模块标签?

In other words, does the updatePolicy of a repository have any effect on the module tags?

推荐答案

modules tag是一个聚合。它与依赖项的处理方式不同。请注意,您在依赖模块中指定的值是不同的。当您声明依赖时,指定 maven坐标。对于模块,您指定相关目录

modules tag is an aggregation. It is not treated the same as dependencies. Notice that the value that you specify in dependency and module is different. When you declare a dependency, you specify maven coordinates. Whilst for module, you specify relative directories.


您最终是否会针对远程服务器的模块或本地模块进行编译?

Will you end up compiling against the remote server's modules, or your local modules?

您将始终最终编译本地模块如果您运行 mvn编译在聚合器模块中(不在子模块中!)子模块依赖项是兄弟依赖项。当您在聚合器模块中 mvn compile 时,在编译子模块时的依赖关系查找将是特殊的。它将从兄弟模块目标文件夹 ONLY 中查看。我找不到相关的文档,但你可以尝试一下。

You will always end up compiling against your local module if you run the mvn compile in the aggregator module (NOT in the child module!) and the child module dependency is a sibling dependency. When you mvn compile in an aggregator module, the dependency lookup when it is compiling the child module will be special. It will look from the sibling modules target folder ONLY. I can't find documentation on this, but you can try it out.

想象一下你有这些聚合器pom

Imagine that you have these aggregator pom

...
<modules>
  <module>child-a</module>
  <module>child-b</module>
</modules>
....

child-b pom声明对child-a的依赖。 (确保你有一个真正的输出类)

child-b pom is declaring a dependency against child-a. (Make sure you have a real output classes)

接下来,当你 mvn编译聚合器pom,child-即使你没有 mvn install child-a,b也能编译。这意味着,child-a甚至不在您的本地存储库中。这是可能的,因为maven将查看child-a类的目标文件夹。要确认这一点,你可以尝试运行 mvn compile clean (是的,编译后清理)。

Next, when you mvn compile the aggregator pom, child-b will be able to compile even if you have NOT mvn install child-a before. That means, child-a is not even in your local repository. This is possible because maven will look into child-a's target folder for the classes. To confirm this, you can try to run mvn compile clean (yes, clean after compile).

再次,请注意,此行为仅适用于从聚合器pom运行它时。如果您当前的工作目录是child-b(依赖于child-a),则当它尝试查找child-a时,它会尊重updatePolicy。

Again, do note that this behavior only applies when you run it from the aggregator pom. If your current working directory is child-b (which is dependent on child-a), it will respect the updatePolicy when it tries to look for child-a.

这篇关于在Maven中,模块是否受到存储库updatePolicy的影响?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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