如何强制 Maven 使用特定的存储库(仅此而已)?

问题描述 投票:0回答:1

我正在设置一个本地 Nexus 存储库,并试图说服我的本地 Maven 设置来访问该存储库作为唯一的存储库。该 Nexus 存储库有一个 maven-central 组,定义为(引用 Nexus 手册:)“...访问中央存储库,以前称为 Maven Central”。并且还应该缓存下载的数据。

因此,我将本地 Nexus 存储库输入到我的 [home]\.m2\settings.xml,如下所示:

    ...
    <profile>
        <id>alwaysActiveProfile</id>
        <repositories>
            <repository>
                <id>RepoSynoProxy</id>
                <name>Nexus Repo on Synology NAS</name>
                <url>http://192.168.1.15:8081/repository/maven-central/</url>
            </repository>
        </repositories>
    </profile>
  </profiles>
  ...
  <activeProfiles>
    <activeProfile>alwaysActiveProfile</activeProfile>
  </activeProfiles>
   ...

但是由于某些奇怪的原因,当我运行 Maven 时,它开始从 https://repo.maven.apache.org/maven2/ 下载所有内容,而不是像我预期的那样从本地 URL 下载:

...
[INFO] Downloading from : http://192.168.1.15:8081/repository/maven-central/junit/junit/3.8.1/junit-3.8.1.pom
[INFO] Downloading from : https://repo.maven.apache.org/maven2/junit/junit/3.8.1/junit-3.8.1.pom
[INFO] Downloaded from : https://repo.maven.apache.org/maven2/junit/junit/3.8.1/junit-3.8.1.pom (998 B at 7.3 kB/s)
[INFO] Downloading from : http://192.168.1.15:8081/repository/maven-central/junit/junit/3.8.1/junit-3.8.1.jar
[INFO] Downloading from : https://repo.maven.apache.org/maven2/junit/junit/3.8.1/junit-3.8.1.jar
[INFO] Downloaded from : https://repo.maven.apache.org/maven2/junit/junit/3.8.1/junit-3.8.1.jar (121 kB at 1.4 MB/s)
...

我的问题是:

首先:任何人都知道,为什么请求http://192.168.1.15:8081/repository/maven-central/...显然不起作用?我在这里使用的是新下载并安装的 Nexus v3.18.0。 Maven 中央代理已经预定义,我没有进行任何特殊配置。显然这不能“开箱即用”。

第二:Maven 在哪里有 URL https://repo.maven.apache.org/maven2/...它用作替代方案?如果存储库不起作用,是否会硬编码到 Maven 中作为后备方案?是否可以抑制这一点,使其仅访问 settings.xml 中定义的存储库?

maven nexus
1个回答
3
投票

您需要在 settings.xml 中配置一个镜像,该镜像将覆盖 superpom 和其他 pom 文件中的存储库定义:https://help.sonatype.com/en/maven-repositories.html

© www.soinside.com 2019 - 2024. All rights reserved.