You’ll frequently want to share Liferay artifacts and modules with teammates or manage your repositories using a GUI. Sonatype Nexus is a valuable tool for managing your repositories. It’s a Maven repository management server that facilitates creating and managing release servers, snapshot servers, and proxy servers. There are several other Maven repository management servers you can use (for example, Artifactory), but this tutorial focuses on Nexus.
To create a Maven repository using Nexus, download Nexus and follow the instructions at http://books.sonatype.com/nexus-book/reference/install.html to install and start it.
To create your own repository using Nexus, follow these steps:
Open your web browser; navigate to your Nexus repository server (e.g., http://localhost:8081/nexus) and log in. The default user name is
Click on Repositories and navigate to Add… → Hosted Repository.
To learn more about each type of Nexus repository, read Sonatype’s Managing Repositories guide.
Enter repository properties appropriate for the type of artifacts it will hold. If you’re installing release version artifacts into the repository, specify Release as the repository policy. Below are example repository property values:
- Repository ID: liferay-releases
- Repository Name: Liferay Release Repository
- Provider: Maven2
- Repository Policy: Release
You just created a Liferay Maven repository accessible from your Nexus repository server! Congratulations!
It’s also useful to create a Maven repository to hold snapshots of each Liferay module you create. Creating a snapshot repository is almost identical to creating a release repository. The only difference is that you specify Snapshot as its repository policy. For example, examine an example snapshot repository’s property values:
- Repository ID: liferay-snapshots
- Repository Name: Liferay Snapshot Repository
- Provider: Maven2
- Repository Policy: Snapshot
Voila! You’ve created a repository for your Liferay releases (i.e.,
liferay-releases) and Liferay snapshots (i.e.,
liferay-snapshots). To learn how to deploy your Liferay Maven artifacts to a Nexus repository, see the Deploying Liferay Maven Artifacts to a Repository tutorial.
Next, you’ll configure your new repository servers in your Maven settings to install artifacts to them.
Configuring Local Maven Settings
Before using your repository servers, you must specify them in your Maven environment settings. Your repository settings let Maven find the repository and retrieve and install artifacts. You can configure your local Maven settings in the
You only need to configure a repository server if you’re sharing artifacts (e.g., Liferay artifacts and/or your modules) with others. If you’re automatically installing Liferay artifacts from the Central/Liferay Repository and aren’t interested in sharing artifacts, you don’t need a repository server specified in your Maven settings. You can find out more about installing artifacts from the Central Repository or Liferay’s own Nexus repository in the Installing Liferay Maven Artifacts tutorial.
To configure your Maven environment to access your
liferay-snapshots repository servers, do the following:
Navigate to your
[USER_HOME]/.m2/settings.xmlfile. Create it if it doesn’t yet exist.
Provide settings for your repository servers. Here are contents from a
settings.xmlfile that has
liferay-snapshotsrepository servers configured:
<?xml version="1.0"?> <settings> <servers> <server> <id>liferay-releases</id> <username>admin</username> <password>admin123</password> </server> <server> <id>liferay-snapshots</id> <username>admin</username> <password>admin123</password> </server> </servers> </settings>
The user name
admin and password
admin123 are the credentials of the default Nexus administrator account. If you changed these credentials for your Nexus server, make sure to update
settings.xml with these changes.
Now that your repositories are configured, they’re ready to receive all the Liferay Maven artifacts you’ll download and the Liferay module artifacts you’ll create!