How to Set Up a Maven Repository In Minutes
A tutorial on how to set up Artifactory as a Maven repository to resolve and deploy artifacts in Maven builds.
Join the DZone community and get the full member experience.
Join For FreeA post published several years ago showed how easy it was to set up Artifactory as a Maven repository to resolve and deploy artifacts in Maven builds. While much water has passed under the bridge since then, and there are new build tools available on the market, I believe that Maven is still popular enough to warrant an update. The competitive landscape for Maven repositories has also changed, but I think that Artifactory is still your best choice for setting one up. In addition to meeting all the criteria for selection in the original article, in its commercial form, Artifactory integrates with all major build tools, all major continuous integration servers and supports all major packaging formats.
Basic Requirements
With the latest version of Artifactory, the only significant requirement you need to concern yourself with is that you’re running JDK 8 update 45 and above. Artifactory comes bundled with its own Tomcat 8 which is used to run the UI as a web application.
You can download Artifactory OSS from JFrog’s download page which pulls the latest version from Bintray. Then extract the Zip file to the location on your file system where you want Artifactory installed. This is your ARTIFACTORY_HOME location.
There are several ways you can install Artifactory, but since that’s not the focus of this article, I’ll just go over the main points you need to install and run it as a service on Windows or Linux.
Linux: Once you have unzipped the Zip file you’re pretty much done. You can now run Artifactory by executing $ARTIFACTORY_HOME/bin/artifactory.sh
or running it as a daemon process using $ARTIFACTORY_HOME/bin/artifactoryctl start
Windows:
- First you need to define the ARTIFACTORY_HOME environment variable and set it to your where you unzipped the download file.
- Now browse to
%ARTIFACTORY_HOME%\bin
and executeInstallService.bat
. You can now start and stop the Artifactory service usingsc start | stop artifactory
To access Artifactory, just go to http://SERVER_DOMAIN:8081/artifactory
. For example, if you are testing on your local machine you should use: http://localhost:8081/artifactory.
This is what you should see once Artifactory starts up.
Log in using the default admin user:
Username: admin
Password: password
Artifactory comes with some Maven repositories out-of-the-box reflecting best practices in Java artifact management. You can view all the repositories in the Artifacts module.
First, configure your Maven client to resolve dependencies through Artifactory. To do that, you need to modify your settings.xml file which is located in the Maven home directory (typically, this will be /user.home/.m2/settings.xml
). All you need to do is click Set Me Up.
(Take note of this screenshot, you’ll need it later when configuring deployment.)
On the Set Me Up dialog, click Generate Maven Settings and select the repositories you want to use to resolve dependencies for your plugins and libraries, both release and snapshot versions.
After clicking Generate Settings, you can copy and paste the generated code into your settings.xml file (or just download the snippet as a new one). Be sure to configure the <server> tag in your settings.xml file with your Artifactory username and password (admin/password by default). The <id> element in this tag will soon be used in your project’s POM file:
You’re almost done.
Let’s also configure Maven to deploy its build through Artifactory. Back in the Artifacts module, select the repository into which you want to deploy your build artifacts and click Set Me Up again (remember that screenshot I asked you to take note of?). Artifactory displays a distributionManagement
snippet already configured for the repository you selected. Simply copy this code snippet and paste it into your project’s POM file. Then match up the <id> element in the <distributionManagement> tag of your POM file to the one you set in the <server> tag of your settings.xml file:
That’s it! You’re ready to do a Maven build that resolves dependencies and deploys its build output through Artifactory. Just run: mvn clean install
As you run the build, you will see that Maven is resolving artifacts through Artifactory.
If you also need to deploy artifacts, Artifactory comes with a set of plugins that allow common CI servers such as Jenkins, TeamCity and Bamboo to direct the build output to Artifactory.
That’s it!
That’s how easy it is to setup a Maven repository in Artifactory. You can even see it in action in this screencast. Artifactory still offers all the benefits presented in the original article and then some:
Reliable and consistent access to remote artifacts: As a proxy for remote repositories, Artifactory caches remote artifacts locally, so you are not dependent on the network or remote resources.
Optimized builds through reduced network traffic: Builds are faster since all remote artifacts are accessed from the local cache without any external networking.
Full integration with any build ecosystem: Through a series of plugins, Artifactory supports fully automated builds using common CI servers both on-premises and in the cloud.
Security and access control: Artifactory provides fine-grained access control from the level of a complete repository down to a single artifact.
License compliance and open source governance: Artifactory performs license checks on your artifacts and all ensuing dependencies. Integration with Black Duck Code Center enables a full range of license compliance and open source governance features.
System stability and reliability: Artifactory supports a High Availability configuration that can provide up to “five-nines” availability.
Distribution and sharing of artifacts across an organization: Local repositories give a central location to store binaries internally. Repository replication lets you share artifacts with different teams around the world.
Artifactory Query Language: A unique query language providing a simple way to formulate complex queries enabling you to dig deep into the endless goldmine of metadata stored in your repositories.
Rich REST API: Almost any action can be performed through a REST API allowing you to fully automate your software delivery pipeline.
Go ahead and give it a try. You can have your first Maven repository setup with Artifactory within minutes. Using Maven has never been easier.
Related Refcard:
Opinions expressed by DZone contributors are their own.
Comments