I'm trying to set up a private remote repository for our team. Now the repository serves the following with so far I have tried -
When a 'mvn compile' is issued, then it searches dependencies in "~/.m2". If it is not found there then it goes to the remote private repository and when the dependencies still absent here then it goes to the central repository.
Before compilation, I have to put all dependencies in our private (and remote) repository along with checksum and metadata.
When we need an artifact(eg - spring-mvc), we need to put it in the remote private repository along with all dependencies of that artifact (spring-mvc). In this case "spring-mvc" is downloaded from our remote private repository. But the dependencies of "spring-mvc" are not downloaded from our remote private repository. They are downloaded from the central repository.
Now what I am trying to do are -
Configuring a private remote repository 'R' in such a way that I do not have to put all the dependencies to it by hand. When a "mvn compile" issued then first of all; dependencies are searched in "~/.m2" if not found then it goes to the private remote repository 'R'. If the dependencies are found in 'R' then "~/.m2" will get it from 'R'. If the dependencies are not found in 'R' then these dependencies are downloaded from the central repositories and keep the dependencies in 'R' for further uses. After that '~/.m2' will get them from 'R'. Here I do not need to put the dependencies in our remote private repository 'R' by hand.
'~/.m2' will get all dependencies of "spring-mvc" (which is the main dependency mentioned in my project's pom.xml) from the remote private repository 'R' and 'R' will get them from the respective central repository.
Can anyone suggest some way/or tutorial for reference to meet these two above targets? Thanks in advance.
EDIT : I have tried with Nathaniel Waisbrot's answer and nexus-2.7.0-06-bundle. After hours of endeavors, I am able to set it up while I am using jre-7. With jre-6, nexus cannot be started. But our project is deployed with JDK-6. We do not want to the change the current jre
version. With jre-6 apache-archiva
is OK. But I am not sure whether I can achieve all the goals in previous section. Is there any archiva
user/expert who can tell me whether I can meet these goals in the previous section?
I have setup
nexus
for mirroring my maven local repository (at~/.m2/repository.
) Since this post is still visited by a lot of people, I think it would be helpful for others if I share how I configurednexus
as a repository manager. This procedure works perfectly for me inUbuntu 12.04
. Here it is -1. Download nexus-2.11.1-01-bundle.tar.gz or latest version of nexus oss.
2. Extract the tar file in you home directory-
Now you will get two directories -
nexus-2.11.1-01
andsonatype-work
in your home directory.3. Copy these two directories to
/usr/local/
directory (they can be copied to other place) -The executable/configuration files related to nexus are stored in
nexus-2.11.1-01
directory and the jar file mentioned inpom.xml
are stored insonatype-work
directory.These jar files are mirror of your
~/.m2/repository
. First time you issue amvn package
command then all thejar
s are stored here. After then when you issuemvn package
again then all jars are downloaded from the nexus repository instead of downloading from the central repository.4. Go to the
/usr/local/
directory -5. Create a link to
nexus-2.11.1-01
-6. Now to run nexus type the following in terminal -
Here nexus is attached with your console. If you close your console then the nexus server will be terminated. When you are trying to run nexus for a Ubuntu server machine then you may use screen.
Note: While trying to run nexus by using the command above there may occur 2 problems. If you do not found any problem then skip next 2 steps (step - 7 and 8)
7. First problem may occur due to insufficient permission. Read the error message and take necessary steps. But as a quick solution you may do this -
8. If you are using any
jdk
version lower than java 7 than the following error message may be shown -In this case use jdk7 to run the command mentioned in step 6. In ubuntu its pretty easy. Assuming you have two jdk - jdk6 and jdk7. Your project runs on jdk6. Then only for running nexus you may do this from your terminal (assuming your jdk7 in
/usr/lib/jvm/jdk1.7.0_45
directory) -9. Now in browser type the address - http://localhost:8081/nexus/. If step 1 to 6 (if errors occurred then step 1 to 8) are done perfectly you may successfully find the login screen. The default login user name is - admin and password is - admin123
10. Stop nexus. Just close the terminal or press Ctrl+C at step 6's terminal. In you
~/.m2
directory create an empty file named -settings.xml
. Copy the following content into thissettings.xml
file -11. And add these following lines in your project's
pom.xml
file -Sonatype Nexus does everything you want, needs very little configuration for what you're asking, and has a nice interface. There's some details on the basic setup under the question "Maven Internal Repository, Is it Really This Hard?"
Basically, you can set up Nexus as a caching repository: your Maven client will only visit the internal repository. When the internal repository can't find an artifact, it goes to Central (or any other external repositories you define), fetches it for you, and stores it for later.
This is cool because if you want to transition from a grab-whatever-dependencies-you-want free-for-all to a locked-down environment, Nexus makes it easy. You set it up to pull from Central, run your build from a clean machine (forcing Nexus to ingest all the current Central dependencies) and then turn off the proxy-repo feature (so any new/changed dependencies will be managed by devops).
What you've described is pretty much the default configuration of most repository managers, including Archiva. Does the following help in getting it set up to use from Maven?
http://archiva.apache.org/docs/1.3.6/userguide/using-repository.html