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

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

Related

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.

Install 3rd Party Libraries with Transitive Dependencies / Dependency Tree?

I am a Maven newbie and spent hours to learn the basics, but I still have not found any good documentation how to install locally a 3rd Party JAR with all its (transitive) dependencies.
I know mvn install:install-file does install a single JAR. But how to install locally in the repsoitory something like this:
+ Parent.jar
+ ChildA.jar (Requuired by Parent)
+ ChildB.jar (Required by Child A)
To make it more complcated and real life: Parent.jar and ChildA.jar are legacy/commercial Jars not available in the public maven Repository but the Child B is a jar that is found in the public repository (for example like a logging jar).
UPDATE: I do not only want to install them locally (with a system dependency) but to also "correctly" integregrate them with maven so i can redistribute this dependency tree to other developers or the public (and I assume this is important for maven), so that maven knows and understands the dependecytree (to avoid version conflicts, unnecessary downloads etc...)
Any links or information how that exaclty describe how this can be done would be great.
Thank you very much!!
Marks
If it's a commercial jar, you may be in violation of the license if you deploy it to a central repository, and the only recourse is to deploy to your company's repo (if you have one setup).
In order to do that you need to define a pom for childA, specifying childB as a dependency, then run the install:install-file goal for that. Then do the same for parent, with childA as it's dependency.
Once you do that, you can then take those items, and upload them pretty easily to your company's central repo through it's GUI (both Nexus and Artifactory support this through the GUI).
Since you actually want to actually publish so that others in the public can use it with the defined dependencies, you pretty much have to get the 3rd party jars into a publicly available repo.
Here are instructions on how to accomplish that.
Please note though, the licensing for the code may not allow you to publish it to a central repo. This is checked before it can be deployed.
I think, you maybe look for this.
Maven will load all needed dependecies into the local repo itself if they are availebale in the online repo. If you want to install your own projects, setup the reactor with profiles to have all wanted modules in it and run mvn install -P yourprofile on it. More about profiles can be found here. Afaik is there no way, to install projects including their dependencies into the local repo.
if you need to install it to a local Maven repository, just use
mvn dependency:go-offline

Merging maven .m2 repositories

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.

How to create local Maven repository for hosting non-Mavenized libraries?

Here's the problem: I love using Maven, as it completely simplifies development and dependency management. However, I'm working with a server which isn't Mavenized, so I can't just add it as a provided dependency. Is there a way to simply specify an additional library folder and add it to the Java compiler classpath, or would I need to actually create an entire local Maven repository for this? I know it completely limits my portability, but I'm okay with that. Thoughts? Also, after compiling, I'll need to copy all of my non-provided dependencies to the local server lib directory, I assume I can use the copy-dependencies plugin to move everything over.
Download Nexus for free from Sonatype, or Artifactory, or any of the other repository managers.
The alternative is to learn about install:install-file to shove jars into your personal local repo. However, having a full repo as above has so many advantages (not the least speed via caching) that it's easier to just install one.
You can use a Maven2 repository implementation such as Nexus, Artifactory, or Archiva.
You can create a simple POM for the non-maven dependency you are working with and use the deploy:deploy-file goal to deploy it to the repository.
If you just need the dependency locally you can use the install:install-file to install the dependency in your local repository. This approach requires nothing more than maven be installed on your machine.
If you just want to add libraries to the path of your build without worrying about repositories you can declare them as system dependencies. I do not recommend this approach but it should work fine.

Categories

Resources