Merging maven .m2 repositories - java

I have a maven repository in an offline network.
I need to update its contents and merge in another repository .
What is the best method to do this ? I looked at the wagon plugin Wagon but I am concerned that there may be a better way.
I could replace my local repo with an offline repository manager but the problem still remains , I would have to update that Repo with regular merges from an online source.

If you can afford to get rid of all metadata (which should recover with the next mvn commands you run) for the time of your operation, just use rsync.
If building a concrete repository is not mandatory, consider using Nexus and its groups.

Vincent's answer is correct, but I would more strongly suggest that you don't do this in the .m2/repository directory. That directory is a cache, and should be able to be removed at any time. You should consider setting up a repository manager (such as Archiva, Nexus or Artifactory, or just a HTTP server) and host the repository content there so that you can let Maven manage the .m2/repository directory.

Related

How can I check if a dependency exists in a remote repository?

I tried with dependency:get or dependency:copy, but those goals will also resolve from my local repo.
Next I tried to make a simple download from https://repo.company.com/repo/<path-to-group>/<artifactId>/<version>/<artifactId>-<version>.pom, but that fails because of missing permissions. I guess that's why I tried to use a plugin, in order to use the existing maven credentials.
Context: Writing a deployment script that should avoid overwriting existing artifacts in our company repo.
A simple approach would be dependency:get, but overriding the local repository on command line with an empty (temporary) directory.
But, as was already said, Artifactory and Nexus are usually configured in a way that they do not override existing artifacts.
local repo override: -Dmaven.repo.local=...

Maven and dependency:sources goals: use alternate repository to download sources?

I am working with an enterprise Nexus repository, whose contents is rather static, meaning it is not a copy of central, but a snapshot at some time.
This Nexus repository does not contains sources classifier. Hence, when I launch one of those goals:
mvn dependency:sources
mvn eclipse:eclipse
I've got a lot, if not all, of dependencies without sources.
What I want to do is pretty simple: I want to tell dependency and eclipse plugins that they should use the central repository only when looking for sources.
If that possible natively?
Can I do that with Nexus and how ?
If you are not even the manager of this Nexus server you are out of luck. You can only work around it by using another Nexus server, maybe installed locally, that does access central as well as your corporate, locked-down instance.
However, most likely, you are not allowed to do that.. locking it down was the reason to have a static repo in the first place.
I would suggest to work with the Nexus administrator to add javadoc and sources to your static repo.
And btw. I have a little tool that can provision a repository called the Maven Repository Provisioner and it can include javadoc and sources. Check it out at https://github.com/simpligility/maven-repository-tools

Archiva / Maven as corporate repository

I am setting up Maven corporate repository using Apache Archiva for my company.
Our requirements for now are quite basic - have an internal repo for our jar files and dependency management.
I want to make sure that Archiva does not upload any of our proprietary code / jar files to Central Repo (Public), but we would like to be able to download public libs from central repo if needed by the project.
(Our desired configuration: IDE/Developer <Download/Upload> Internal Repository <DOWNLOAD ONLY> Public Central Repo.)
My question is, by default, does Archiva upload my jar files to central repo if its configured as a proxy/mirror? if so, how do I prevent publishing to central/external repo while keeping the option to download from central when needed?
Appreciate any answers.
If you configure the local/managed repository which is linked to Central as read-only, then nobody can upload to it. This is done by only giving the "Repository Observer" role but not the "Repository Admin" (in fact you will most likely add additional roles, just make sure none of them is assigned for any developer to one of the mirrored repos).
BTW: you can also disallow re-deploy (aka overwrite of artifact versions) for a repository. This is generally a good idea. This is done in the repository settings (not by roles).
One additional thing you might want to look for: if you configure a repo to be Snapshot only, it still will accept SNAPSHOT uploads. This can be quite confusing, make sure nobody does that.

Make my local .m2 folder as a repository

Is it possible to make the .m2 folder in my local machine a repository so that other team members can use my repository instead of checking anywhere else and get the dependencies from mine? I have seen http://www.sonatype.org/nexus/go but there, we have to upload all dependencies manually.
Can we make .m2 folder (in some machine) a maven repository so others can use it?
The important thing with you local repository is that it's stable. If you were to put it on a shared drive, everytime one of you team builds, the artifacts that the rest of the team see will change - development being what it is, this would be a nightmare as the bugs that are introduced while developing would immediately effect the whole team rather than being isolated to one person (the assumption here is that you have multiple artifacts and build with mvn install).
The correct way to do this is to setup a repo, that proxies the public Maven repos. Both Nexus and Artifactory are setup to do this out of the box and are very easy to install on either Windows or Unix. The proxy feature means that your repo only need contain the artifacts produced by your team and the repository will retrieve other artifacts from the public Maven repos as needed (often storing them for future use).

Maven downloading from central repository

I am on Netbeans and don't know Maven much. Whenever I import, open some Maven project, it starts donwloading something from some central repository, sometimes huge. It downloads things in .m2\repository.cache\m2e. I have limited bandwidth and don't want this. How to stop this?
I have set Options>Java>Maven>Dependency Download Strategy to never. Also tried mvn -o install and mvn -o for offline. Not solved.
The Maven way is to get you what the project says it needs, but you have not already downloaded to your local repository.
The huge file is the list of what is actually available in Maven Central, and for some reason unknown to me it is downloaded on a regular basis. If you do it once, it should be kept for future sessions.
Maven will download all the dependency only once to the local repository and not again and again.
Weather you have limited or unlimited bandwidth you have to download it to execute your project.
Maven has a very modular architecture. That means the the thing you get when you download the Maven distribution is in reality small core functionality.
The rest is downloaded from a Maven artifact repository, like Maven Central (which is the default repo).
Note that this applies not only for dependencies (the library your project uses), but also your plugins (i.e. the stuff that compiles, packages, and otherwise builds the projects). Hence the large number of downloads.
Like the other answers said, if you don't delete your local repository it should eventually contain all the artifacts (dependencies and plugins) you need without re-downloading. The only exception are SNAPHSOT dependencies which can get re-downloaded periodically, depending what's in your POM and settings.
Ultimately, you have two possibilities:
If you have access to a higher-bandwith connection somewhere, you can build the projects while using it, and your local repo will still store the needed artifacts.
If you have several computers/configurations behind a local network, you can set up a Maven repository manager, like Nexus or Artifactory, and use it as a local mirror. Note that those still need to download the artifacts at first as well.
But there isn't much else you can do. "Maven downloading the Internet" is, unfortunately in your case, by design.

Categories

Resources