Skip to content
Advertisement

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

I got following error while trying to build the project. The project is spring project and use IntelliJ with 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)

Is there a way to fix it through setting.xml? I have not access to any configuration on http://maven:8081/nexus/content/groups/public

This is my setting.

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

Advertisement

Answer

If you set

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

then you send every request to this repository, regardless of the rest of the settings.xml. You need to do something like

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

but please also correct/remove the URLs as khmarbaise said.

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement