The liferay-plugin-package.properties file is used to list dependencies from the portal’s jars. At deployment time, Liferay will copy the listed jars from the portal’s WEB-INF/lib directory to the artifact’s WEB-INF/lib directory. Defining dependency jars this way reduces the size of your deployment war (since the jars do not need to be included in the war) and maximizes compatibility with the portal (since the portal and the artifact will be using the same version of the jar).
When using the Liferay SDK, the ant build process will honor dependencies listed in liferay-plugin-package.properties at compile time, greatly simplifying the ant project setup.
The Maven build process, however, does not honor the dependencies listed in liferay-plugin-package.properties. For Maven, all dependencies must be listed in the pom.xml file such as:
<dependency> <groupId>commons-lang</groupId> <artifactId>commons-lang</artifactId> <version>2.6</version> </dependency>
When you list a Maven dependency in this manner, Maven will include the jar file in the target WEB-INF/lib directory, effectively defeating the purpose of using the liferay-plugin-package.properties file. In fact, listing the dependency in the pom.xml file as well as in the liferay-plugin-package.properties file will result in duplicate jars in the deployed artifact’s WEB-INF/lib directory. The maven dependency will be there with the full jar filename (which typically includes the version number, for example) and the portal’s jar will be there with the shortened jar name.
So you basically have two choices:
- Use the normal Maven dependency declarations in the pom.xml file and do not use the liferay-plugin-package.properties file.
- Use the Maven dependency declarations with the scope provided and use the liferay-plugin-package.properties file.
Your choice here depends upon how much you value the smaller deployment wars and the maximized portal compatibility. If those are not your concerns, you may opt for the easier and standard Maven dependency declarations.
If you do want to use the liferay-plugin-package.properties file approach, you need to add the scope provided to those dependencies you plan on pulling from Liferay:
<dependency> <groupId>commons-lang</groupId> <artifactId>commons-lang</artifactId> <version>2.6</version> <scope>provided</scope> </dependency>
Care should be taken to use the same version that Liferay will be copying in as to avoid runtime conflicts. Often times the version is best found by opening the dependent Liferay jar file and reading the META-INF/MANIFEST.MF file.
When you add the provided scope, Maven will not include the dependency in the target WEB-INF/lib directory at build time, so you must have the dependency listed in liferay-plugin-package.properties. Then Liferay will copy in the dependency at deployment time.
The provided scope allows you to use Maven dependencies yet still have a smaller war file for deployment.