Unresolved requirement: Import-Package: com.liferay.portal.kernel.portlet.bridges.mvc; version="[2.0.0,3.0.0)"

8.8k views Asked by At

I have downloaded Liferay 7.3.5 Community Edition from here and trying to deploy a HelloWorld portlet for testing purposes. It is bundled with Tomcat. I am using Liferay Developer Studio (the same old Eclipse on steroids) for developing and deploying the portlet. Version 3.8.1.202004240132-ga2 I have also created a Server like in this link - the server is using the tomcat 9.0.37 from the already downloaded bundle.

After steps above, I have followed steps from here to create a Module Project and to deploy it on the already started tomcat server. The portlet appears in the deployed section, but with a red "x" near it: enter image description here

I went to add the portlet/widget in a widget page that I have created for this purpose, but I could not find the portlet: enter image description here

Then, logged in with an admin user, I went to Control Panel -> App Manager and searched for my Portlet. It appears as "Installed" and I can activate it. After I hit "Activate", Eclipse logs start writing: ERROR [http-nio-8080-exec-8][PortletServlet:119] javax.portlet.PortletException: org.osgi.framework.BundleException: Could not resolve module: VictorTestPortlet [2716]_ Unresolved requirement: Import-Package: com.liferay.portal.kernel.portlet.bridges.mvc; version="[2.0.0,3.0.0)"_ [Sanitized]

enter image description here

The Question: what is causing this error ?

2

There are 2 answers

2
Olaf Kock On BEST ANSWER

You found the complex solution yourself, there are two simpler ways:

  1. Use the target platform. Assuming you're using Liferay Workspace, your gradle.properties in the root of your workspace has an entry liferay.workspace.target.platform.version. Set it to 7.3.5 and the versions will be taken automagically

  2. Have even the required modules be detected automagically by setting the target platform, and declare your dependency as

    dependencies { compileOnly group: "com.liferay.portal", name: "release.portal.api" }

This will even figure out the exact module (of more than 1000) that you need to depend on. Granted, it kind of works against the whole concept of modularization (to be aware of your dependencies), but it's soooo convenient.

0
Victor On

The problem is as it is already stated - the dependency is not found.

To fix this, I went in build.gradle file that is missing a version for the "com.liferay.portal" dependency. So, my line was looking like this:

compileOnly group: "com.liferay.portal", name: "com.liferay.portal.kernel"

And now it is looking like this:

compileOnly group: "com.liferay.portal", name: "com.liferay.portal.kernel", version: "9.8.1"

The version MUST be the same as found in your Liferay Server instance - you can find it by accessing the portal-kernel.jar and looking into its MANIFEST.MF file for the key "Bundle-Version". The jar is located in ...portal-tomcat-7.3.5\tomcat-9.0.37\lib\ext folder.

Good luck !