【问题标题】:How do I force Maven to use external repos to retrieve artifacts?如何强制 Maven 使用外部存储库来检索工件?
【发布时间】:2021-06-16 21:12:16
【问题描述】:

我在尝试构建项目时遇到以下错误。该项目是 spring 项目,使用 IntelliJ 和 java 8。

Could not find artifact org.springframework.data:spring-data-bom:pom:2021.0.0-M2 in nexus (http://maven:8081/nexus/content/groups/public)

有没有办法通过setting.xml修复? 我无法访问 http://maven:8081/nexus/content/groups/public 上的任何配置

这是我的设置。

<settings
xmlns="http://maven.apache.org/SETTINGS/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0
                    http://maven.apache.org/xsd/settings-1.0.0.xsd">

<servers>
    <server>
        <id>releases</id>
        <username>me</username>
        <password>mee</password> <!-- impossible password here :-) -->
    </server>
    <server>
        <id>snapshots</id>
        <username>me</username>
        <password>mee</password> <!-- impossible password here :-) -->
    </server>
    <server>
        <id>nexus</id>
        <username>me</username>
        <password>mee</password> <!-- impossible password here :-) -->
    </server>
</servers>

<mirrors>
    <mirror>
        <!--This sends everything else to /public -->
        <id>nexus</id>
        <mirrorOf>*</mirrorOf>
        <url>http://maven:8081/nexus/content/groups/public</url>
    </mirror>
</mirrors>

<profiles>
    <profile>
        <id>nexus</id>
        <!--Enable snapshots for the built in central repo to direct -->
        <!--all requests to nexus via the mirror -->

        <repositories>
            <repository>
                <id>central</id>
                <url>https://mvnrepository.com/repos/central</url>
                <releases><enabled>true</enabled><updatePolicy>always</updatePolicy></releases>
                <snapshots><enabled>true</enabled><updatePolicy>always</updatePolicy></snapshots>
            </repository>
        </repositories>

        <pluginRepositories>
            <pluginRepository>
                <id>central</id>
                <url>https://mvnrepository.com/repos/central</url>
                <releases><enabled>true</enabled><updatePolicy>always</updatePolicy></releases>
                <snapshots><enabled>true</enabled><updatePolicy>always</updatePolicy></snapshots>
            </pluginRepository>
        </pluginRepositories>
    </profile>

    <profile>
        <id>defaultprofile</id>
        <!-- if you want to be able to switch to the defaultprofile profile put this in the active profile -->

        <repositories>
            <repository>
                <id>maven.default</id>
                <name>default maven repository</name>
                <url>http://repo1.maven.org/maven2</url>
                <releases><enabled>true</enabled><updatePolicy>always</updatePolicy></releases>
                <snapshots><enabled>true</enabled><updatePolicy>always</updatePolicy></snapshots>
            </repository>
            <repository>
                <id>maven.snapshot</id>
                <name>Maven snapshot repository</name>
                <releases><enabled>true</enabled><updatePolicy>always</updatePolicy></releases>
                <url>http://people.apache.org/repo/m2-snapshot-repository</url>
                <snapshots><enabled>true</enabled><updatePolicy>always</updatePolicy></snapshots>
            </repository>
            <repository>
                <id>vaadin-addons</id>
                <url>https://maven.vaadin.com/vaadin-addons</url>
            </repository>
        </repositories> 
    </profile>
</profiles>

<activeProfiles>
    <!--make the profile active all the time -->
    <activeProfile>nexus</activeProfile>
</activeProfiles>

【问题讨论】:

  • 首先这些条目:https://mvnrepository.com/repos/central 完全错误...删除它们。其次这些条目:http://repo1.maven.org/maven2 不需要。也删除它们。如果您喜欢使用 Spring Boot 的里程碑版本,则必须将其添加到您的存储库管理器中,而不是您的 pom 文件中,因为您已经在使用存储库管理器。
  • 请评论我的答案,而不是编辑它。

标签: java maven repository settings pom.xml


【解决方案1】:

如果你设置了

    <mirrorOf>*</mirrorOf>
    <url>http://maven:8081/nexus/content/groups/public</url>

然后您将每个请求发送到此存储库,而不管settings.xml 的其余部分如何。你需要做类似的事情

    <mirrorOf>*,!central</mirrorOf>
    <url>http://maven:8081/nexus/content/groups/public</url>

但也请按照 khmarbaise 的说法更正/删除 URL。

【讨论】:

  • 我确实添加了&lt;mirror&gt; &lt;!--This sends everything else to /public --&gt; &lt;id&gt;nexus&lt;/id&gt; &lt;mirrorOf&gt;*,!central&lt;/mirrorOf&gt; &lt;url&gt;http://maven:8081/nexus/content/groups/public&lt;/url&gt; &lt;/mirror&gt; 并删除了其余部分,但错误仍然存​​在。
  • 你是用-U构建的吗,所以mvn clean install -U
  • 不,我只是做 mvn clean install
  • 然后使用-U 重试,以避免由于缓存导致的错误。
猜你喜欢
  • 2016-02-06
  • 1970-01-01
  • 1970-01-01
  • 2013-06-05
  • 2021-07-04
  • 2011-02-04
  • 2015-07-11
  • 1970-01-01
  • 2012-09-30
相关资源
最近更新 更多