How to integrate between Apache Archiva and Maven

Apache Archiva is a great remote repository manager. It’s very important to implement it especially in large project, which involve many developers using same dependency libraries.

Why you need Apache Archiva?

Q : Let’s assume a new team member just joined your team, and for sure the new member will take a very long time in the first time building process because it’s required to download the dependency libraries from Maven central repository.

A : With help of Apache Archiva, you have own central repository in your team, you are connect to your own repository instead of Maven central repository. It cut off the long first time building process and good in centralize the dependency libraries in your project.

Integration

The Apache Archiva and Maven integration is quite straightforward is easy

1. Install Apache Archiva

Install the Apache Archiva

2. Default configuration

Two default remote repositories are configure automatically.

Basically, all the default settings are enough for the Maven integration.

3. Add mirror setting

Locale the Maven’s configuration file, “{mavendir}/conf/settings.xml “, update the mirror setting to your Apache Archiva repository.


<mirrors>
    <!-- mirror
     | Specifies a repository mirror site to use instead of a given repository. The repository that
     | this mirror serves has an ID that matches the mirrorOf element of this mirror. IDs are used
     | for inheritance and direct lookup purposes, and must be unique across the set of mirrors.
     |
    <mirror>
      <id>mirrorId</id>
      <mirrorOf>repositoryId</mirrorOf>
      <name>Human Readable Name for this Mirror.</name>
      <url>http://my.repository.com/repo/path</url>
    </mirror>
     -->
	<mirror>
		<id>internal</id>
		<name>Proxy Cache - Internal Repository</name>
		<url>http://localhost:8080/archiva/repository/internal</url>
		<mirrorOf>*</mirrorOf>
	</mirror>

  </mirrors>

* url tag – It is your Archiva remote repository sever address.
* mirrorOf tag – mirror everything

P.S More detail about Maven mirror settings

4. Done

The different!?

Here’s the different before and after the Apache Archiva integration.

Before integrate Archive

All the dependency libraries are download from Maven central repository.


E:\project\projectname>mvn compile
[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[INFO] Building projectname Maven Webapp
[INFO]    task-segment: [compile]
[INFO] ------------------------------------------------------------------------
[INFO] [resources:resources {execution: default-resources}]
[INFO] Copying 0 resource
Downloading: http://repo1.maven.org/maven2/log4j/log4j/1.2.14/log4j-1.2.14.pom
Downloading: http://repo1.maven.org/maven2/log4j/log4j/1.2.14/log4j-1.2.14.jar
[INFO] [compiler:compile {execution: default-compile}]

After integrated Archive

All the dependency libraries are download from your own remote repository (Archiva) server.


E:\project\projectname>mvn compile
[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[INFO] Building projectname Maven Webapp
[INFO]    task-segment: [compile]
[INFO] ------------------------------------------------------------------------
[INFO] [resources:resources {execution: default-resources}]
[INFO] Copying 0 resource
Downloading: http://localhost:8888/archiva/repository/internal/log4j/log4j/1.2.14/log4j-1.2.14.pom
2K downloaded  (log4j-1.2.14.pom)
Downloading: http://localhost:8888/archiva/repository/internal/log4j/log4j/1.2.14/log4j-1.2.14.jar
358K downloaded  (log4j-1.2.14.jar)
[INFO] [compiler:compile {execution: default-compile}]

About the Author

author image
mkyong
Founder of Mkyong.com, love Java and open source stuff. Follow him on Twitter. If you like my tutorials, consider make a donation to these charities.

Comments

avatar
4 Comment threads
1 Thread replies
0 Followers
 
Most reacted comment
Hottest comment thread
2 Comment authors
Sarfaraj SayyadShantha KumarApache Archiva Tutorials | J2EE Web Development TutorialsHow to add remote repositories in Apache Archiva | Maven Recent comment authors
newest oldest most voted
Sarfaraj Sayyad
Guest
Sarfaraj Sayyad

How if we don’t have that artifacts or dependency artifacts on central repository( here we can say at “http://localhost:8888/archiva/repository/internal” ). Is that getting downloaded automatically ? or what are the steps/settings we have to follow to getting downloaded artifacts automatically ?

FYI -> I am using apache-archiva-1.4-M2

Thanks in advance.
/Sarfaraj

Sarfaraj Sayyad
Guest
Sarfaraj Sayyad

is it possible ?

Shantha Kumar
Guest
Shantha Kumar

Apache archiva not downloading artifacts from maven repository..

trackback
Apache Archiva Tutorials | J2EE Web Development Tutorials

[…] Integrate Apache Archiva and Maven A guide to integrate Maven and Apache Archiva together. […]

trackback
How to add remote repositories in Apache Archiva | Maven

[…] Make sure you configured the Maven mirror setting […]