2.3. Developing Plugins Using Maven
2.3.2. 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.
Liferay 6.2 Developer Guide Page 55 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.
2.3.2.1. 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.
Release servers hold software that has met the software provider's criteria for planned features and quality. Snapshot servers hold software that is in a state of development. 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. The default username is admin with password admin123.
2. Click on Repositories and navigate to Add... → Hosted Repository.
Liferay 6.2 Developer Guide Page 56 Note: To learn more about each type of Nexus repository, read Sonatype's Managing Repositories at http://www.sonatype.com/books/nexus-book/reference/confignx-sect-manage-repo.html.
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.
Liferay 6.2 Developer Guide Page 57 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 them.
2.3.2.2. 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.
Note: You only need to configure a repository server if you're installing downloaded Liferay CE/EE artifacts from a zip file or if you want to share artifacts (e.g., Liferay artifacts and/or your plugins) with others. If you're automatically installing Liferay CE artifacts from the Central Repository and aren't interested in sharing artifacts, you don't need a repository server specified in your Maven settings.
However, configuring a mirror in your Maven settings is recommended as a best practice. Get more information on mirrors and their purpose in Maven's guide on mirrors at
http://maven.apache.org/guides/mini/guide-mirror-settings.html.
To configure your Maven environment to access your liferay-releases repository server, do the following:
1. Navigate to your [USER_HOME]/.m2/ directory. Create that directory if it doesn't yet exist.
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"?>
<settings>
<servers>
<server>
<id>liferay-releases</id>
<username>admin</username>
<password>admin123</password>
Liferay 6.2 Developer Guide Page 58
</server>
<server>
<id>liferay-snapshots</id>
<username>admin</username>
<password>admin123</password>
</server>
</servers>
</settings>
Note: The username admin and password admin123 are the credentials of the default Nexus OSS 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 plugin artifacts you'll create!
Now, let's install the Liferay artifacts you'll need to create your plugins.