我如何强制 Maven 使用外部存储库来检索工件?

How do I force Maven to use external repos to retrieve artifacts?

我在尝试构建项目时遇到以下错误。该项目是 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>

如果你设置

    <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>

但也请 correct/remove khmarbaise 所说的 URL。