There are some topics, which i discussed/searched a solution for through the Stackoverflow over the past years. Occasionally I need some of them again and again, that’s why i wanted to summarize those here, and this is one of them.
My post was:
I recently wanted to integrate Nexus to my home-based Java Project, just to learn what it is good for. As i read from the posts on the internet, and from the nexus Website, its main usage aim is:
- Maven Central Repo has more than 200k artifacts. Get a local copy of your artifacts. Do not download every time you need them. When you specify an artifact, first nexus will be asked if it has the artifact, if yes it will be read from your local cache. if not nexus will download it from the central repo. Your build will continue to work regardless of the original artifact in Central Repo. Speed up your builds etc.
Now what i don’t understand here is: Is it not the same as maven does? First time when i define a new artifact in a pom.xml, the jar will be downloaded from the central repo. It will be placed in ~/.m2/repository. Next time it will be read from here as long as there is a copy of it. Even if i create a new project, the downloaded jars will be used from this repository.
I think, I would need Nexus if i have another developer in my network, who also needs these jars. So we would not need to download these jars separately from central. We would define a network based repo (Nexus) and the jars would be downloaded to this repository. Other developers would reach this repo without the need of reaching central repo.
In my case, i cant see any advantages of nexus. I now have this settings.xml which Nexus suggests to use:
<pre><code> <settings xmlns="http://maven.apache.org/SETTINGS/1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd"> <localRepository/> <interactiveMode/> <usePluginRegistry/> <offline/> <pluginGroups/> <servers/> <mirrors> <mirror> <!--This sends everything else to /public --> <id>nexus</id> <mirrorOf>*</mirrorOf> <url>http://localhost:8081/nexus/content/groups/public</url> </mirror> </mirrors> <profiles> <profile> <id>nexus</id> <!--Enable snapshots for the built in central repo to direct --> <!--all requests to nexus via the mirror --> <repositories> <repository> <id>central</id> <url>http://central</url> <releases><enabled>true</enabled></releases> <snapshots><enabled>true</enabled></snapshots> </repository> </repositories> <pluginRepositories> <pluginRepository> <id>central</id> <url>http://central</url> <releases><enabled>true</enabled></releases> <snapshots><enabled>true</enabled></snapshots> </pluginRepository> </pluginRepositories> </profile> </profiles> <activeProfiles> <!--make the profile active all the time --> <activeProfile>nexus</activeProfile> </activeProfiles> <proxies/> </settings> </code></pre>
The jars i have in /.m2/repository/ directory are exactly same as the jars in http://localhost:8081/nexus/content/groups/public/
. What is the advantage of Nexus in my case?
A part of the answer, which i may find useful in the future is:
- You can set up your own hosted repository and deploy your snapshot releases (complete with timestamp in the version name) “for real” – rather than just with -SNAPSHOT as in your .m2 cache
- It’s a great way to learn how real Maven repositories work, which is an important skill inside a larger organization (and which you don’t want to learn through trial-and-error on a production Nexus repo).