设置 Maven 来编译(而不是下载)依赖项

Setting up maven to compile (instead of downloading) dependencies

我克隆了 Apache ActiveMQ Artemis 项目 (https://github.com/apache/activemq-artemis) 的 git 存储库,然后输入

mvn -Ptests test -pl :integration-tests

我很惊讶地看到如下日志消息

...
Downloading: http://repository.apache.org/snapshots/org/apache/activemq/artemis-selector/1.4.0-SNAPSHOT/artemis-selector-1.4.0-20160625.030221-11.jar
Downloading: http://repository.apache.org/snapshots/org/apache/activemq/artemis-core-client/1.4.0-SNAPSHOT/artemis-core-client-1.4.0-20160625.030211-11.jar
...

因为例如artemis-core-client 包含在我一开始克隆的 git 存储库中,我本以为 Maven 会从那里构建它。

这样,当我在核心客户端源中进行更改时,它们会被集成测试选中。

相反,maven 正在从存储库下载 jar。

问题:如何配置 maven 始终构建 git 存储库中的所有模块并仅下载 "true" 依赖项,我的意思是东西不在 git 存储库中?

您没有在主项目上执行 Maven 构建,在主 pom.xml 上确实定义了 artemis-selectorartemis-core-client 模块等。

您正在 tests and its pom.xml 上执行 Maven 构建,其中仅定义了测试模块。这是一个 side/test 项目,它以先前的 pom 文件作为父文件,但在其父模块定义中没有任何作用。因此,依赖项不是作为模块而是作为 Maven 依赖项来解析的。

您应该首先安装(通过mvn clean install)之前的项目,这样库就可以在本地Maven缓存中使用(因此不会触发下载),然后执行tests项目.


检查 Maven docs 以了解继承与聚合的区别以进一步阐明它。

来自 Stack Overflow 的以下线程也可能很有趣:

  • Maven multi module project cannot find sibling module