Maven Checks the local repository but downloads from central. Why? - maven

We have a local artifactory repository setup for caching. It is configured in our projects, but when I'm looking at stdout of the build process I see rows like this
Downloading: http://ourserver/artifactory/our-repo/javax/transaction/jta/1.1/jta-1.1-sources.jar
Downloading: http://repo1.maven.org/maven2/javax/transaction/jta/1.1/jta-1.1-sources.jar
Downloaded: http://repo1.maven.org/maven2/javax/transaction/jta/1.1/jta-1.1-sources.jar (25 KB at 54.5 KB/sec)
So it looks like it is trying to download the jar from the local repository AND from Maven Central and then actually uses Maven Central).
If I copy the url of the local repository in my browser I get the jar without a problem.
If I check with the admin application of artifactory I can see the artefact.
Can anybody explain why Maven Central is used at all?
UPDATE: What was going on and what I did:
orien's answer explaines why Maven Central was accessed at all.
mliebelt comments hinted me towards my solution: Looks like our local repository was to slow to answer when it had to download the artifact first. I configured the cache to eagerly download jars and sources when a pom gets requested. This should reduce the number of artifacts downloaded from elsewhere.

Maven can be configured with multiple repositories. Adding a repository, as you have in your project, does not invalidate any repositories you have already configured. By default everyone gets the repository at Maven Central. Maven is then free to download an artifact from any repository it has available.
Sounds like what you really want to do is set up a mirror. You can configure a mirror in your settings.xml file:
<mirrors>
<mirror>
<id>our-server-repo</id>
<name>our local repository</name>
<url>http://ourserver/artifactory/our-repo</url>
<mirrorOf>*</mirrorOf>
</mirror>
</mirrors>
Note that we've used a wildcard (*) in the mirrorOf element. This specifies that all repositories will be accessed via the specified URL. With this configuration Maven will only access your local Artifactory repository.

Related

How does Maven use external dependencies in your own project?

I had a quick question on how Maven configures dependencies in the pom.xml file. In my project's pom.xml file, when I add a dependency tag and provide the artifact id and group id, how/where does Maven store those dependencies to use in my project? Since Maven is a central repository, does Maven use the internet to pull the dependencies or does it download the repositories in your local machine and use it from there?
Maven repository is of three types :
Local
Central
Remote
Maven first starts finding in Local Repository created by Maven in %USER_HOME% directory. To override the default location, mention another path in Maven settings.xml file available at %M2_HOME%\conf directory.
When Maven does not find any dependency in a local repository, it starts searching in the Central repository.
Sometimes, Maven does not find a mentioned dependency in the central repository as well. It then stops the build process and output error message to console. To prevent such situation, Maven provides a concept of Remote Repository, which is the developer's own custom repository containing required libraries or other project jars.
For user-defined jars, you also need to specify :
<repositories>
<repository>
<id>in-project</id>
<name>Name_of_your_project</name>
<url>file://${project.basedir}/libs</url>
</repository>
</repositories>
In standard configuration, Maven looks first in your local Maven repository (.m2/repository in your user directory) and if it does not find anything, it tries to download from the remote repositories that you specified. If you did not specify any, it will use MavenCentral.
When Maven finds something, it will be downloaded to the local Maven repository for future use. If you have -SNAPSHOT dependencies, they will be updated regularly.

How to use Sonatype Nexus Repository Groups with Github raw repositories?

How can I tell Nexus to download the artifacts from a raw github maven repository when the Proxy Repository in Nexus is in a Repository Group?
Background: In our parent-pom we use a catch all mirror, so we don't have to configure each and every repository to the poms. This works flawless and is also common practice - example:
<mirrors>
<mirror>
<id>provided</id>
<url>http://nexus.host/content/groups/provided</url>
<mirrorOf>*</mirrorOf>
</mirror>
</mirrors>
But when using a raw github repository this dosn't works. How can I configure Nexus to do this?
Note: I already read "How to add Github raw repositories to Sonatype Nexus as Proxy repository?", but this doesn't tells you how it would run with Repository Groups.
Update: In a manual post step I created the nexus index files with the nexus-indexer-3.0.4-cli.jar, and commited/pushed them to github. Now nexus shows me in the "Browse Index" tab the files in the Proxy Repository, but the problem remains. Clients can not download the artifacts from Nexus.
After creating the proxy repository, you have to add it to the group through which you are accessing Nexus in your build tool. In your case it seems that group uses the id "provided" as visible from the url in the mirror.
See more about adding to repository groups in the Nexus book here and here

Divert to locally stored maven-install-plugin

I tried to upload a Windows build to Nexus with the Maven Commandline:
mvn deploy:deploy-file -Durl=http://unity.apps.company.net/nexus/content/repositories/idesktopbuildimages-releases/ -DrepositoryId=idesktopbuildimages-releases -DgroupId=images.WINDOWS7X64EnterpriseSP0unattendedcapture.sources -DartifactId=install -Dversion=6.4 -Dpackaging=wim -Dfile=install.wim
And got the error:
Downloading:
http://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-clean-plugin/2.4.1/maven-clean-plugin-2.4.1.pom
[WARNING] Failed to retrieve plugin descriptor for
org.apache.maven.plugins:maven-clean-plugin:2.4.1: Plugin
org.apache.maven.plugins:maven-clean-plugin:2.4.1 or one of its
dependencies could not be resolved: Failed to read artifact descriptor
for org.apache.maven.plugins:maven-clean-plugin:jar:2.4.1
This happens because I don't have Internet access (only Intranet access).
So is there the possibility to divert to a locally stored maven-install-plugin file in my Maven Command?
PS: I tried -DpomFile but got the same output.
Solution:
Adding the Proxy settings to my settings.xml
If you don't have internet access, I assume you have a mirror of maven central available on your intranet. If it's the case you must configure your settings.xml to declare the mirror. So add something like that in your settings.xml file:
<mirrors>
<mirror>
<id>central-mirror</id>
<name>Local mirror of central repo</name>
<url>http://unity.apps.company.net/nexus/content/repositories/central</url>
<mirrorOf>central</mirrorOf>
</mirror>
</mirrors>
EDIT
Other thing to look at : you may need to configure some proxy settings (it seems strange that they aren't already there...)
see this
You have to set up your settings file to access the public group of Nexus as described in the Nexus book and ensure that your Nexus server has access to Central.
The url for the public group should be .../nexus/content/groups/public. This default group has the "Central" repository in it.
If you are using a different group like your "releases" you should ensure that the Central repository (or Maven Central in older Nexus releases) is part of the list of ordered group repositories as visible at http://books.sonatype.com/nexus-book/reference/confignx-sect-managing-groups.html#fig-group-config
Once that is set you can confirm that the Central repository is reachable by checking out the the proxy repository Central itself in the repositories view and confirm that you can access the remote repo by using the "Browse Remote" tab visible in http://books.sonatype.com/nexus-book/reference/confignx-sect-manage-repo.html#fig-repo-config
If this browsing does not work you Nexus server is most likely blocked by an internal proxy server. If that is the case you have to configure it in Administration - Server - Default HTTP Proxy Settings.

How can I get Nexus to grab artifact files in proxy repositories?

My setup is that I have a local Maven repository on my machine, and one on my team's machine that's managed by Nexus. I added a new proxy repository to Nexus. When I select this new proxy repository and hit "Browse Remote", I see everything (all the JARs, POM files, etc.) in the repository, as it should be. But when I click "Browse Storage", I see almost nothing ... only a handful of POM files, and none of the JAR files.
My Maven build is failing, presumably because it can't get the JAR files from Nexus (the JARs don't appear in my local repository, either, but the POMs do). The other virtual repositories on my Nexus all have the JAR files in storage and in my local repository; how can I get Nexus to grab the JAR artifacts from the remote repository?
I'm sure this is something basic, but I've searched and didn't come up with anything I can use. Thank you!
Enable remote repository index download, add the repository to the public group, make sure that Maven hits Nexus and most importantly read the free book about Nexus.
Here is the chapter about configuring Maven to work with Nexus.
Oh and for proxy repositories it will only download remote artifacts if they are needed e.g. by a Maven build accessing Nexus..
I just ran into this issue as well and thought it might help to have another answer.
I have my repository location at: http://serverName.company.com/nexus-2.3 and I copied/pasted that URL into my settings.xml file. That nexus server points to another company's nexus server so that we only have to point to one to pull down our stuff as well as theirs. Unfortunately, I wasn't able to do that.
That is, until I found out that you have to use the following URL instead of the one above:
http://serverName.company.com/nexus-2.3/content/groups/public/
The snippet of my settings.xml looks like:
<mirror>
<id>nexus</id>
<mirrorOf>*</mirrorOf>
<url>http://serverName.company.com/nexus-2.3/content/groups/public/</url>
</mirror>
I spent far too long figuring this out. I hope this helps someone in the future.

Why does Nexus repository doesn't download the required artifacts when using a group repository?

I use Nexus repository manager and configured the default .../nexus/content/groups/public/ repository and added maven central, codehaus snapshot and an internal respository that I created and have uploaded few artifacts to that.
Then added .../nexus/content/groups/public to mirror in settings.xml. When I do a maven build, maven looks in .../nexus/content/groups/public but does not update org.apache.maven.plugins:maven-site-plugin:pom:2.0-beta-6 and reports that it is not found.
But if I remove the mirror from settings.xml, then it looks in http://repo1.maven.org/maven2/ and it picks up all the artifacts correctly.
I have also changed publish url to true. What do I miss?
If you added the repositories as proxy repositories in Nexus do not forget to add the proxies to the Repository Group which you use as mirror for all Nexus requests (public/snapshot) - assumed you have this kind of configuration.

Resources