Our documentation has been relocated here, the Liferay Developer Network. Please update your bookmarks!

Using Maven repositories

Wouldn’t it be nice to install and deploy your Liferay artifacts to a repository? Great news! Maven lets you install your artifacts to your machine’s local repository and even deploy them to remote repositories; so you can share them privately with your team or with the public for general consumption. Your local repository holds your downloaded artifacts and those artifacts you install to it. Remote repositories are for sharing artifacts either privately (e.g., within your development team) or publicly. To learn more about using artifact repositories see http://maven.apache.org/guides/introduction/introduction-to-repositories.html.

Maven also lets you configure a proxy server; it mediates your requests to public Maven repositories and caches artifacts locally. Using a local proxy/repository helps you build projects faster and more reliably. You want this for two reasons: accessing remote repositories is slower, and remote repositories are sometimes unavailable. Most Maven proxy servers can also host private repositories that hold only your private artifacts. If you’re interested in running your repository behind a proxy, see http://www.sonatype.com/books/nexus-book/reference/install-sect-proxy.html.

Now that you’ve been introduced to Maven repositories and proxy servers, let’s consider using a repository management server to create and manage your Maven repositories.

Managing Maven Repositories

You’ll frequently want to share Liferay artifacts and plugins with teammates, or manage your repositories using a GUI. For this, you’ll want Nexus OSS. It’s a Maven repository management server that facilitates creating and managing release servers, snapshot servers, and proxy servers. If you’re not interested in using Nexus as a repository management server, feel free to skip this section.

Let’s create a Maven repository using Nexus OSS. If you haven’t already, download Nexus OSS from http://www.sonatype.org/nexus/ and follow instructions at http://www.sonatype.com/books/nexus-book/reference/_installing_nexus.html to install and start it.

To create a repository using Nexus, follow these steps:

  1. Open your web browser; navigate to your Nexus repository server (e.g., http://localhost:8081/nexus) and log in.

  2. Click on Repositories and navigate to Add…Hosted Repository.


    Figure 9.1: Adding a repository to hold your Liferay artifacts is easy with Nexus OSS.

  3. Enter repository properties appropriate to the access you’ll provide its artifacts. We’re installing release version artifacts into this repository, so specify Release as the repository policy. Below are examples of repository property values:

    • Repository ID: liferay-releases
    • Repository Name: Liferay Release Repository
    • Provider: Maven2
    • Repository Policy: Release
  4. Click Save.

You just created a Maven repository accessible from your Nexus OSS repository server! Congratulations!

Let’s create a Maven repository to hold snapshots of each Liferay plugin we create. Creating a snapshot repository is almost identical to creating a release repository. The only difference is that we’ll specify Snapshot as its repository policy:

  1. Go to your Nexus repository server in your web browser.

  2. Click on Repositories and navigate to Add…Hosted Repository.

  3. Specify repository properties like the following:

    • Repository ID: liferay-snapshots
    • Repository Name: Liferay Snapshot Repository
    • Provider: Maven2
    • Repository Policy: Snapshot
  4. Click Save.

Voila! You not only have a repository for your Liferay releases (i.e., liferay-releases), you also have a repository for your Liferay plugin snapshots (i.e., liferay-snapshots).

Let’s configure your new repository servers in your Maven environment so you can install artifacts to the them.

Configuring Local Maven Settings

Before using your repository servers and/or any repository mirrors, you must specify them in your Maven environment settings. Your repository settings enable Maven to find the repository and get access to it for retrieving and installing artifacts.

To configure your Maven environment to access your liferay-releases repository server, do the following:

  1. Navigate to your ${USER_HOME}/.m2/ directory.

  2. Open your settings.xml file. If it doesn’t yet exist, create it.

  3. Provide settings for your repository servers. Here are contents from a settings.xml file that has liferay-releases and liferay-snapshots repository servers configured:

    <?xml version="1.0"?>

Now that your repositories are configured, they’re ready to receive all the Liferay Maven artifacts you’ll download and the Liferay plugin artifacts you’ll create!

Now, let’s install the Liferay artifacts you’ll need to create your plugins.

0 (0 Votes)
Installing Maven Previous