Mirror and repository in Maven are two easily confused concepts, as both are used to configure the addresses of remote Maven repositories. As the name suggests, a repository directly configures the site address, while a mirror acts as a site’s mirror, proxying requests to one or several sites, achieving a complete replacement of repositories.
Repository
There are two ways to configure multiple repositories: configuring multiple profiles or configuring multiple repositories within a single profile. When configuring multiple profiles, you also need to configure activeProfiles for the configurations to take effect.
Single profile, multiple repository configuration is also similar.
This way, multiple site configurations are achieved. When downloading dependencies, Maven will try to download from each address in the order configured from top to bottom, until a successful download is made.
Mirror
In my opinion, the existence of mirror is somewhat redundant. If you don’t want to use the address configured in the repository, you can simply change it directly, without adding another mirror configuration.
If both settings.xml and pom have configured repositories, the configured mirror can take effect on both configuration files, which may be the only meaning of mirror’s existence.
Use mirrorOf to specify which repository this mirror targets. Setting it to * means it will proxy requests to all repositories.
Note that, unlike repositories, when multiple mirrors are configured for the same repository, they are in a backup relationship with each other. They will only switch to another one when the repository is unreachable. If the repository is reachable but a package cannot be found, it will not try the next address.
Therefore, in general, whether configuring domestic Maven repositories or configuring private repositories like Nexus, you can directly configure them as repositories. This way, even if some of these configured repositories have issues and some packages cannot be downloaded, you can still try other repositories.