Maven 3 Nexus - Unable to download artifacts from remote Repository - maven

I have a Maven 3 Nexus installed on a server. Through the Nexus GUI, I have added a proxy repository of repository policy as "Snapshot" and the URL is a remote Vendor URL, from where the artifacts/plugins are required to be downloaded. Then I have added the newly added proxy repository to the Public Repositories under Ordered Group Repositories.
Post the above activity, I have tried to build the project using mvn clean install. However the build is failing due to missing artefacts from vendor URL.
In Nexus, when I go under the Public repository and look under Browse storage, I do not see the artefact folder, which should have been downloaded from remote repository.
The "Browse remote" on the newly created repository is working fine and I can navigate to the required artifacts.
I am not sure what I am doing wrong. Any help is much appreciated.

If while the first run of :
mvn clean install
the required artefact was not available on Nexus, maybe it is now cache localy (on your laptop) as not found.
Maybe you just have to tell maven to update cache using -U option ?
mvn clean install -U
The other solution could be a mismatch snapshot/release repository information. Check your Repository policy proxy configuration on your Nexus server proxy.

Related

Configure nexus repository to only store jars that are installed (selected by me)

I would like to configure a nexus repository to only manage jars that I install. Right now it also retrieves jars from maven central and stores them in the repository. I don't want that to happen.
Can anyone point me in the right direction how this can be achieved?
When you say to store the "jars that are installed" , if you are referring to the artifacts being created by your project, you can have a hosted maven repository snapshot/release and use maven deploy plugin to upload it on to your nexus repository.
You can either create a profile in your pom and activate in your install it on mvn install phase to upload the artifacts to your nexus repository.

Replicate nexus repository in my local server

I work in an organisation and we use nexus repositories. I want a simple approach of how can I replicate few groups from nexus repository in to local server so that maven downloads the dependencies from local server and not from nexus.
If you use local server in the sense of base machine then you use clean install as a maven goal. The build code will be available under .m2/repository folder.
Install Nexus locally, create Proxy Repository for each of the repo or group that you want to have locally. In Proxy Repository you'd need to set up URLs to the remote repos.
Now point Maven to this local Nexus (e.g. with <mirrors> in settings.xml). First time Maven downloads a dependency it will go to Local Nexus which would grab the dependency from the remote one. This file is going to be cached in Local Nexus and further downloads won't hit the Remote Nexus.
PS: don't know why you would do this.

Unable to find resource 'opensymphony:quartz-all:pom:1.6.3' in repository central

I inherited this project which used to build & run successfully (years ago...). Now when checked out from version control, as is, it complains:
Unable to find resource 'opensymphony:quartz-all:pom:1.6.3' in
repository central (http://repo1.maven.org/maven2)
But following that repository link (http://repo1.maven.org/maven2) leads to a browsable site that shows clearly that this resource is available: http://search.maven.org/#browse|1030701351 !
I have even been able to manually download it, and I can also find it in my local repo (C:\maven\repo\opensymphony\quartz-all\1.6.3\quartz-all-1.6.3).
So, my questions:
Why is Maven complaining at all, if it is there?
How did it get to my local repo, if Maven couldn't find it?
Your local repository is NOT in C:\maven ... it is in your users directory ~/.m2/repository
To debug what is really going on I would suggest to deactivate the ~/.m2/settings.xml (e.g. by renaming it) and do a clean build without any of the old artifacts and from a fresh local repository (just delete ~/.m2/repository)
That would tell you what is really missing.
If anything is missing that means it is not in the Centra Repository (http://search.maven.org). As a next step I would then install a repository manager in your network. I would recommend using Sonatype Nexus (open source, free book as documentation) and then add any other repositories or missing artifacts in there.

What is meant by local repository and remote repository in Maven?

I am reading up Maven - The complete reference and came across this
Maven assumes that the parent POM is available from the local repository, or available in the parent directory (../pom.xml) of the current project. If neither location is valid this default behavior may be overridden via the relativePath element.
What exactly is meant by local and remote repository for a Maven installation and a project?
A local repository is a local directory structure that caches artifacts downloaded from remote repositories, or those that are manually installed (eg from the command line option).
A remote repository is a web service (defined by a URL) that contains versioned artifacts. This might be as simple as an Apache server, or a full-blown Maven repository, such as Artifactory, that allows uploading, permissions based on a user directory, etc.
http://maven.apache.org/guides/introduction/introduction-to-repositories.html
By default, Maven will source dependencies from, and install dependencies to, your local .m2 repository. This is a precedence rule, and your .m2 acts like a cache where Maven can source dependencies before downloading them remotely. You can bypass this behaviour like so: mvn -U ... (see mvn --help).
Your local .m2 can be found under C:\Users\{user}\.m2 on Windows, or /home/{user}/.m2 on Linux. If you do a mvn install, your project will be locally installed under the said .m2 repository.
A remote repository is a Maven repository, just like your local .m2 repository, hosted for you to source dependencies from, e.g. Maven Central.
Local repository is a repo. Into your local system, when you compile or install project all required dependencies downloaded into your local repo.
When you're working with your project, then Maven first tries to get dependencies from local. If it's not available, then Maven will try to download the dependency from a central repository.
central repo. is a online repo, which is provided by maven itself.

maven could not resolve dependency via my local nexus repository

I have setup an in-house Sonatype Nexus repository and configure the maven to check my local Nexus instead of getting artifacts directly from public repositories.
http://www.sonatype.com/books/nexus-book/reference/config-sect-intro.html
Our project was able to download the most artifacts except one artifact in Maven central.
Here is the build error:
Failed to execute goal on project shindig-gadgets: Could not resolve dependencies for project org.apache.shindig:shindig-gadgets:jar:3.0.0-SNAPSHOT: Could not find artifact com.ibm.icu:icu4j:jar:4.6 in nexus (http://my_nexus_repository:8081/nexus/content/groups/public) -> [Help 1]
I see that icu4j-4.6.jar does exist in the Maven central repository. On my local nexus repository, it doesn't exist. I see only icu4j-4.6.pom exists on my local nexus repository.
It's not like my nexus repository setting is totally broken. maven project has successfully downloaded numerous jar files from multiple public repositories via my local nexus maven repository except icu4j-4.6.jar.
I don't understand why I'm having a problem with only icu4j-4.6.jar. Would it be incorrectly cached on either my local maven or nexus maven repository?
If it was incorrectly cached, how can I clean the local maven or nexus maven repository?
The similar problem is described at
Missing maven dependency using nexus setup
icu4j-4.6.jar does not show up in the search list. Only icu4j-4.6.pom shows up in the search list. I don't think is Snapshot VS Release issue because icu4j-4.6.jar seems release jar.
Is it possible that the nexus repo just stopped responding for a while? You can try mvn -X (or -d?) to get detailed info about what is going on. You might also try configuring an alternative repo.
Perhaps you haven't enabled remote index downloads from Maven Central. This would explain why only the POM file appears in your local search (The only file which has been downloaded via the proxy repo).
There might be another issue causing the download failure for the jar itself.... I suppose try and solve one problem at a time :-)
Try adding -U to your mvn arguments to force an update of your local repository.
You could also have corrupt meta data in the repo. In which case, delete that artifact from the repo's cache and let it refresh.
If the artifact in question was cached in properly from the proxy repository, using mvn -U will fix the problem
However if you are seeing pom on your nexus ,this usually happens when the artifact from the proxy repository is not cached in properly. The way to fix is
1) Browse to the component in the Proxy Repository.
2) Invalidate the cache for the repository and reindex the Nexus repository.
3) run mvn clean -U

Resources