简体   繁体   English

Maven为什么要从远程存储库下载模块

[英]Why does Maven want to download a module from a remote repository

Given the following modules in my pom.xml 在我的pom.xml中给出以下模块

<modules>
  <module>core</module>
  <module>middle-layer</module>
  <module>top-layer</module>
<modules>

Where top-layer depends on middle-layer which depends on core. 顶层取决于中间层,而中间层取决于核心。

When I run clean install it will build and install core and middle-layer successfully, but not top-layer. 当我运行clean install ,它将成功构建并安装核心层和中间层,而不是顶层。 It tries to download middle-layer from a remote repository instead of using the freshly built one in the local repository. 它尝试从远程存储库下载中间层,而不是使用本地存储库中新构建的中间层。

I do have a custom remote repository specified in my pom.xml: 我确实在pom.xml中指定了一个自定义的远程存储库:

 <repositories>
    <repository>
        <id>custom</id>
        <url>http://someaddress/maven2/</url>
        <snapshots>
            <updatePolicy>never</updatePolicy>
        </snapshots>
        <releases>
            <updatePolicy>never</updatePolicy>
        </releases>
    </repository>
</repositories>

Why does it want to grab middle-layer from the remote repository? 为什么要从远程存储库中获取中间层?

Currently, everything is in SNAPSHOT-mode. 当前,一切都处于SNAPSHOT模式。

Middle layer dependency: 中间层依赖性:

<dependencies>
    <dependency>
        <groupId>mygroup</groupId>
        <artifactId>core</artifactId>
        <version>2.0.1-SNAPSHOT</version>
    </dependency>
</dependencies>

Top layer dependency: 顶层依赖性:

<dependencies>
    <dependency>
        <groupId>mygroup</groupId>
        <artifactId>middle-layer</artifactId>
        <version>2.0.1-SNAPSHOT</version>
    </dependency>
</dependencies>

They all inherent their versions from the parent (currently at 2.0.1-SNAPSHOT) and I'm calling install from the parent pom. 它们都是父版本的固有版本(当前版本为2.0.1-SNAPSHOT),我从父pom调用install。

Maven frequently prints messages about downloading things that it is not, in fact, downloading. Maven经常打印有关下载实际上不是下载的内容的消息。 It is considering the possibility that there is a newer snapshot available remotely than the last one build locally. 它正在考虑是否存在比本地上一个快照更高的远程快照。 This is why uploading snapshots is often a really bad idea. 这就是为什么上传快照通常不是一个好主意的原因。

I found the answer. 我找到了答案。

It was a typical problem between keyboard and chair. 这是键盘和椅子之间的典型问题。

The middle-layer is actually historically a WAR, not a JAR, that is to say: it includes some classes I needed in my top-layer. 从历史上看,中间层实际上是WAR,而不是JAR,也就是说:它包括一些我顶层中需要的类。 (It's not really called middle-layer of course). (当然,它并不是真正的中间层)。 So top-layer searches for middle-layer.jar and can't find it (because it's a WAR). 因此,顶层搜索middle-layer.jar并找不到它(因为它是一个WAR)。

So I have to refactor some stuff to get the things I need from middle-layer into a new library JAR and make both middle-layer and top-layer depend on that instead. 因此,我必须重构一些东西,以便将我需要的东西从中间层转移到新的JAR库中,并使中间层和顶层都依赖于此。

Sorry to waste your time. 抱歉浪费您的时间。 :) :)

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

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