Replicate nexus repository in my local server - maven

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.

Related

Nexus repo not accessible through proxy in maven settings

I have a maven project.
when I build using cmd prompt- It downloads the maven repos, only when the proxy is configured in settings.xml file.
But this proxy is blocking the nexus repos. I do have two nexus repos required for this project. and I get build error -- return code:503 reason phrase: service unavailable for nexus repo contents
If I follow the stack overflow answer Nexus Repo gives 503 with Maven but not with browser
and added proxy to nexus instance and mirrored the nexus in my settings file. Still maven repo works and nexus repos or not accessible.
my settings.xml
Any help would be appreciated.
Thanks in advance

Directly transferring a .pom file from local maven repo to remote repo

I have a maven "pom-only" artifact in my local repository (which is not built by me or my company , It was an very old one ). I want to transfer this to remote repository (our companies snapshot repository) . How do i do that .
I have following in my local repo under the version folder
****-1.8-SNAPSHOT.pom
****-1.8-SNAPSHOT.pom.sha1
How can i push both to remote repo. One of our project is dependent on this parent/Pom only artefact ?
The Web UI of your remote repository manager should provide functionality to upload/deploy artifacts manually. For Artifactory and Nexus I know for sure that they provide such.

Maven - Disable local repository completely and only go to remote

I have set up nexus on a server and now I would like to ensure that my local machine only uses nexus to get any dependencies and never goes to its local .m2 directory.
Is there a recommended way to do this and in fact is this even recommended at all?
Thanks
You always have to use your local .m2 directory, because otherwise Java would not be able to put the JARs to classpath.
If you always want to update your local repositories with the versions from e.g. Nexus, then use "mvn -U" or "mvn --update-snapshots" which "Forces a check for updated releases and snapshots on remote repositories" according to http://books.sonatype.com/mvnref-book/reference/running-sect-options.html.
Otherwise remote repositories are only checked daily if there is already an artifact within local repository.

how to upload my local repository to archiva

I am setting up an apache archiva instance to server as our development team's local repository. I'd like to initially seed it with the artifacts in my local .m2 repository. However, as far as I can tell, the depoly plugin and the repository plugin work only with individual projects. I have also configured my local settings.xml file to deploy artifacts to archiva when built with maven, as shown in the archiva documentatation. Also, I'm aware that it's possible to upload artifacts via archiva's webUI form. This would still require me to upload jars individually. Is there a way to automate this or do some sort of mass upload?
deploy plugin can do it for you. (use deploy-file goal)
See http://maven.apache.org/plugins/maven-deploy-plugin/file-deployment.html

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.

Resources