Using external artifacts in your project requires configuring their dependencies. To do this, look up the artifact’s attributes and plug them into dependency entries for your build system (either Gradle, Maven, or Ant/Ivy). Your build system downloads the dependency artifacts your project needs to compile successfully.
Before specifying an artifact as a dependency, you must first find its attributes. Artifacts have these attributes:
- Group ID: Authoring organization
- Artifact ID: Name/identifier
- Version: Release number
This tutorial shows you how to make sure your projects have the right dependencies:
- Find Core artifacts
- Find Liferay app and independent artifacts
- Configure dependencies
Finding Core Artifacts
Each Liferay artifact is a JAR file whose META-INF/MANIFEST.MF
file contains
the artifact’s OSGi metadata. The manifest also specifies the artifact’s
attributes. For example, these two OSGi headers specify the artifact ID and
version:
Bundle-SymbolicName: [artifact ID]
Bundle-Version: [version]
This table lists the group ID, artifact ID, version, and origin for each core Liferay DXP artifact:
Core Liferay DXP Artifacts:
File | Group ID | Artifact ID | Version | Origin |
---|---|---|---|---|
portal-kernel.jar | com.liferay.portal | com.liferay.portal.kernel | (see JAR’s MANIFEST.MF ) | fix pack ZIP, Liferay DXP installation, or Liferay DXP dependencies ZIP |
portal-impl.jar | com.liferay.portal | com.liferay.portal.impl | (see JAR’s MANIFEST.MF ) | fix pack ZIP or Liferay DXP .war |
portal-test.jar | com.liferay.portal | com.liferay.portal.test | (see JAR’s MANIFEST.MF ) | fix pack ZIP or Liferay DXP .war |
portal-test-integration.jar | com.liferay.portal | com.liferay.portal.test.integration | (see JAR’s MANIFEST.MF ) | fix pack ZIP or Liferay DXP .war |
util-bridges.jar | com.liferay.portal | com.liferay.util.bridges | (see JAR’s MANIFEST.MF ) | fix pack ZIP or Liferay DXP .war |
util-java.jar | com.liferay.portal | com.liferay.util.java | (see JAR’s MANIFEST.MF ) | fix pack ZIP or Liferay DXP .war |
util-slf4j.jar | com.liferay.portal | com.liferay.util.slf4j | (see JAR’s MANIFEST.MF ) | fix pack ZIP or Liferay DXP .war |
util-taglibs.jar | com.liferay.portal | com.liferay.util.taglib | (see JAR’s MANIFEST.MF ) | fix pack ZIP or Liferay DXP .war |
com.liferay.* JAR files | com.liferay | (see JAR’s MANIFEST.MF ) | (see JAR’s MANIFEST.MF ) | fix pack ZIP, Liferay DXP installation, Liferay DXP dependencies ZIP, or the OSGi ZIP |
Next, you’ll learn how to find artifacts for Liferay DXP apps and independent modules.
Finding Liferay App and Independent Artifacts
Independent modules and modules that make up Liferay DXP’s apps aren’t part of the Liferay DXP core. You must still, however, find their artifact attributes if you want to declare dependencies on them. The resources below provide the artifact details for Liferay DXP’s apps and independent modules:
Resource | Artifact Type |
---|---|
App Manager | Deployed modules |
Reference Docs | Liferay DXP modules (per release) |
Maven Central | All artifact types: Liferay DXP and third party, module and non-module |
The App Manager is the best source for information on deployed modules. You’ll learn about it next.
App Manager
The App Manager knows what’s deployed on your Liferay DXP server. You can use it to find whatever modules you’re looking for.
Follow these steps to get a deployed module’s information:
-
In Liferay DXP, navigate to Control Panel → Apps → App Manager.
-
Search for the module by its display name, symbolic name, or related keywords. You can also browse for the module in its app. Whether browsing or searching, the App Manager shows the module’s artifact ID and version number.
If you don’t know a deployed module’s group, use the Felix Gogo Shell to find it:
-
Open a Gogo Shell session by entering the following into a command prompt:
telnet localhost 11311
This results in a
g!
: the Felix Gogo Shell command prompt. -
Search for the module by its display name (e.g.,
Liferay Bookmarks API
) or a keyword. In the results, note the module’s number. You can use it in the next step. For example, these results show the Liferay Bookmarks API module’s number is52
:g! lb | grep "Liferay Bookmarks API" 52|Active | 10|Liferay Bookmarks API (2.0.1)
-
To list the module’s manifest headers, pass the module number to the
headers
command. In the results, note theBundle-Vendor
value: you’ll match it with an artifact group in a later step:g! headers 52 Liferay Bookmarks API (52) -------------------------- Manifest-Version = 1.0 Bnd-LastModified = 1464725366614 Bundle-ManifestVersion = 2 Bundle-Name = Liferay Bookmarks API Bundle-SymbolicName = com.liferay.bookmarks.api Bundle-Vendor = Liferay, Inc. Bundle-Version = 2.0.1 ...
-
Disconnect from the Gogo Shell session:
g! disconnect
-
On Maven Central or MVNRepository, search for the module by its artifact ID.
-
Determine the group ID by matching the
Bundle-Vendor
value from step 3 with a group listed that provides the artifact.
Next, you’ll learn how to use Liferay DXP’s reference documentation to find a Liferay DXP app module’s attributes.
Reference Docs
Liferay DXP’s app Javadoc lists each app module’s artifact ID, version number, and display name. This is the best place to look up Liferay DXP app modules that aren’t yet deployed to your Liferay DXP instance.
Follow these steps to find a Liferay DXP app module’s attributes in the Javadoc:
-
Navigate to Javadoc for an app module class. If you don’t have a link to the class’s Javadoc, find it by browsing https://docs.liferay.com/dxp/apps.
-
Copy the class’s package name.
-
Navigate to the Overview page.
-
On the Overview page, search for the package name you copied in step 2.
The heading above the package name shows the module’s artifact ID, version
number, and display name. Remember, the group ID for all app modules is
com.liferay
.
Next, you’ll learn how to look up artifacts on MVNRepository and Maven Central.
Maven Central
Most artifacts, regardless of type or origin, are on
MVNRepository
and
Maven Central.
These sites can help you find artifacts based on class packages. It’s common to
include an artifact’s ID in the start of an artifact’s package names. For
example, if you depend on the class
org.osgi.service.component.annotations.Component
, search for the package name
org.osgi.service.component.annotations
on one of the Maven sites.
Now that you have your artifact’s attribute values, you’re ready to configure a dependency on it.
Configuring Dependencies
Specifying dependencies to build systems is straightforward. Edit your project’s build file, specifying a dependency entry that includes the group ID, artifact ID, and version number.
Note that different build systems use different artifact attribute names, as shown below:
Artifact Terminology
Framework | Group ID | Artifact ID | Version |
---|---|---|---|
Gradle | group | name | version |
Maven | groupId | artifactId | version |
Ivy | org | name | rev |
The following examples demonstrate configuring a dependency on Liferay’s Journal API module for Gradle, Maven, and Ivy.
Gradle
Here’s the dependency configured in a build.gradle
file:
dependencies {
compileOnly group: "com.liferay", name: "com.liferay.journal.api", version: "1.0.1"
...
}
Maven
Here’s the dependency configured in a pom.xml
file:
<dependency>
<groupId>com.liferay</groupId>
<artifactId>com.liferay.journal.api</artifactId>
<version>1.0.1</version>
</dependency>
Ivy
Here’s the dependency configured in an ivy.xml
file:
<dependency name="com.liferay.journal.api" org="com.liferay" rev="1.0.1" />
Nice! Now you know how to find artifacts and configure them as dependencies. Now that’s a skill you can depend on!
Related Topics
Adding Third Party Libraries to a Module
Third Party Packages Portal Exports