How to use mirrorOf in Maven - maven

What is the difference between using
<mirrorOf>central</mirrorOf>
and
<mirrorOf>*</mirrorOf>
We have a Nexus server running proxied to the Maven public repository and using "*" instead of "central" downloads some artifiacts but not all.
Reading http://maven.apache.org/guides/mini/guide-mirror-settings.html does not suggest what could cause this ?

<mirrorOf>central</mirrorOf>
says if request comes to lookup for central maven repository look in its mirror instead
where
<mirrorOf>*</mirrorOf>
says for any request to download from any repository look in this mirrored repository
if you have second and if it is failing to download some artifacts it could be because you are not proxying certain repository in your own nexus repository

Related

How to Change Maven repository to inbuilt repository in same network

In our project we need to setup a repository in a remote machine and I need to point to that repository. I have tried changing settings.xml.
But that didn't work. Then I added repository directly in pom.
This works. But still I am seeing the artifacts are downloaded from central repository. When I checked the effective pom, I am seeing that central repository is been mentioned along with mentioned internal repository
I dont need artifacts to be downloaded from central repository. Instead I need to download from my remote repository. How can I achieve it. TIA :)
You can force Maven to use a single repository by having it mirror all repository requests. The repository must contain all of the desired artifacts, or be able to proxy the requests to other repositories. This setting is most useful when using an internal company repository with the Maven Repository Manager to proxy external requests.
To achieve this, set mirrorOf to *.
<settings>
...
<mirrors>
<mirror>
<id>internal-repository</id>
<name>Maven Repository Manager running on repo.mycompany.com</name>
<url>http://repo.mycompany.com/proxy</url>
<mirrorOf>*</mirrorOf>
</mirror>
</mirrors>
...
</settings>
more details here

Maven cannot pull jars from Mirros

We have a central repository within intranet. I set mirror as follow. The issue is when I try to download a dependency that is not available in my local repository, the dependency cannot be downloaded completely. Only .lastUpdated file is downloaded in directory. I cannot figure out whey this weird thing happened. But it I comment the mirror setting, the dependency could be downloaded correctly. But I need some ourselves developed dependencies that are residing on central repository. That means I cannot bypass the central repository to search on internet. Does anyone come across this creepy issue?
<mirror>
<id>central-proxy</id>
<name>Central Repo</name>
<url>http://*.*.*.*.*/artifactory/repo</url>
<mirrorOf>*</mirrorOf>
</mirror>
</mirrors>

Difference between using a single repository and a single mirror

The maven documentation says:
http://maven.apache.org/guides/mini/guide-mirror-settings.html
Using A Single Repository. You can force Maven to use a single
repository by having it mirror all repository requests. The repository
must contain all of the desired artifacts, or be able to proxy the
requests to other repositories. This setting is most useful when using
an internal company repository with the Maven Repository Manager to
proxy external requests.
To achieve this, set mirrorOf to *.
<settings>
...
<mirrors>
<mirror>
<id>internal-repository</id>
<name>Maven Repository Manager running on repo.mycompany.com</name>
<url>http://repo.mycompany.com/proxy</url>
<mirrorOf>*</mirrorOf>
</mirror>
</mirrors>
...
</settings>
I don't understand this paragraph.
Shouldn't it be something like this?
Using A Single Mirror You can force Maven to use a single
mirror by having it mirror all repository requests. The mirror must contain all of the desired artifacts for all the
repositories, or be able to proxy the requests to other
repositories. This setting is most useful when using an internal
company repository with the Maven Repository Manager to proxy external
requests. To achieve this, set mirrorOf to *.
<settings>
...
<mirrors>
<mirror>
<id>internal-mirror</id>
<name>Maven Mirror Manager running on mirror.mycompany.com</name>
<url>http://mirror.mycompany.com/proxy</url>
<mirrorOf>*</mirrorOf>
</mirror>
</mirrors>
...
</settings>
Where is my miss-understanding?
I mean, <mirror><id>internal-repository</id>... seems just wrong to me.
Mirror means a repository that is used as a passerelle/proxy to an other repository.
When using a repository manager like Nexus, Artiafactory, Archiva... you dispose of one local entreprise repository wich proxifies remotes ones.
So there is no need to declare too many repositories in your pom or setting.xml. Using Just one mirror which redirect all requests to the repository manager you have will be sufficient.
That is the meaning of the documentation.
As maven documentation says:
Repositories can be declared inside a project, which means that if you have your own custom repositories, those sharing your project easily get the right settings out of the box. However, you may want to use an alternative mirror for a particular repository without changing the project files.
For repositories in settings.xml, declaring mirrors for them is redundant because you can just replace the repositories directly. You should use mirrors for repositories in pom.xml.
For example. Project X is a public project that list all the repos it required in its pom.xml.
Most people can just download and build the project directly.
Alex wants to build the project on his working PC at company, and his company has an internal enterprice repo. So he uses the company repo in his settings.xml as a mirror for the project repos.
Bob cannot access some project repos directly due to connection issue. He can use other public mirrors for that repo.
Repos in pom.xml is used as default implements and mirrors should be used for special cases.

What will be url for the archiva central repository?

In an example how to configure apache archiva this code should be added to the settings.xml ..but the url is not working what to do ?
<mirror>
<id>archiva.central</id>
<url>http://192.168.1.7:8081/archiva/repository/internal</url>
<mirrorOf>central</mirrorOf>
</mirror>
The archiva documentation /internal/ points to the repository which is default configured to proxy the maven central repository. They use it with a trailing slash, maybe this helps you?
Is the URL accessible via web browser? Did you also add the repository to your POM?

How to create a local central repository for maven artifacts

My organization uses maven for all our projects. Every time we create new maven project, the artifacts are downloaded from maven central repository. But i want to create organization level local repository where all the maven artifacts are available and when new maven project created should look for the artifact in local repository and if not found, then only look in the maven central repository. Can anyone let me know how to do this.
Thanks.
You should take a look at Sonatype Nexus repository manager. It can be used as a proxy to cache remote repositories. After Nexus has been set up, you will just have to edit your settings.xml and add something like this:
<mirrors>
<mirror>
<id>nexus-proxy</id>
<name>Nexus Proxy</name>
<url>http://nexus.example.com/nexus/content/groups/public</url>
<mirrorOf>central</mirrorOf>
</mirror>
</mirrors>
You could use Artifactory or a similar Repository Management tool

Resources