简体   繁体   English

在检查联系之前,Maven构建依赖项

[英]Maven build dependencies before checking nexus

I am building my multi module project using the command 我正在使用命令构建我的多模块项目

mvn clean deploy -DskipTests

This project has 3 maven modules: A, B, C. 该项目包含3个Maven模块:A,B,C。

A doesn't depend on anything. A不依赖任何东西。

B doesn't depend on anything. B不依赖任何东西。

C depends on A. C取决于A。

I am getting a very weird scenario where maven sees that C depends on A and then instead of building A from the sources it decides to check nexus for it (as my .m2 local repository doesn't contain A) and it fetches an old version of A. Then it goes on building everything, but when it reaches C it uses that old version of A and fails. 我遇到一个很奇怪的情况,maven看到C依赖于A,然后决定从源代码中构建A,而是决定检查它的关系(因为我的.m2本地存储库不包含A),并且它获取了旧版本然后继续构建所有内容,但是当到达C时,它将使用旧版本的A并失败。

If I run my build in offline mode then it works great, but the problem is that I do want to deploy my new artifacts in nexus when I am done, and maven offline mode restricts me from doing that. 如果我以离线模式运行构建,那么它将很好用,但是问题是我确实想在完成后将新的工件部署在nexus中,而maven离线模式限制了我这样做。

I am wondering if I am doing something really weird, this seems like a pretty easy to handle scenario. 我想知道我是否在做一些很奇怪的事情,这似乎很容易处理。

Edit: If I login to nexus and i manually delete all the old artifacts and then build with the command provided above, everything works fine. 编辑:如果我登录到nexus,并且手动删除了所有旧工件,然后使用上面提供的命令进行构建,则一切正常。

Edit 2: C depends on A with a "provided" scope, something like : 编辑2:C取决于A的“提供”范围,例如:

 <dependency>
     <groupId>com.test</groupId>
     <artifactId>application</artifactId>
     <scope>provided</scope>
     <type>jar</type>
 </dependency>

(version is declared in dependencyManagement section of the parent pom). (版本在父pom的dependencyManagement部分中声明)。

Options: 选项:

  1. Commit A so that you get the latest changes and C builds fine 提交A,以便获得最新的更改,C可以正常构建

  2. Make C depend on a specific version of A. Update the version of A and make C depend on it 使C依赖于A的特定版本。更新A的版本并使C依赖于它

Turns out the problem was related to the Espresso Testing framework in android. 原来问题与android中的Espresso Testing框架有关。 One of the android dependencies in the pom.xml was set with <scope>test</scope> instead of <scope>provided</scope> and that was causing the trouble described. pom.xml中的一个android依赖项是使用<scope>test</scope>而不是<scope>provided</scope> ,这引起了描述的麻烦。

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

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