'Liferay rest-build project unresolved requirement problem

I'm trying to deploy a Liferay rest-builder project. These are the steps I follow to do it:

  1. I create a rest-builder project with Liferay Developer Studio wizard.
  2. I edit the *-impl/rest-openapi.yaml file
  3. I launch the buildREST Gradle task
  4. BuildREST task ends successfully
  5. I launch the deploy Gradle task
  6. Deploy task ends successfully
  7. When JAR tries to deploy, it lets this message in log:
Unable to start bundle: file:/C:/devs/testlr73/bundles/osgi/modules/com.liferay.training.service.rest.impl.jar
org.osgi.framework.BundleException: Could not resolve module: com.liferay.training.service.rest.impl [1368]_  Unresolved requirement: Import-Package: com.liferay.portal.vulcan.pagination; version="[1.4.0,2.0.0)"

I tried this operation with versions 7.1, 7.2, 7.3 and 7.4.

Only 7.4 deploys without a problem (after fix the version in the javax.xml.bind dependency).

I was trying found where is set the Import-Package to fix it but I can't found it.



Solution 1:[1]

There are two general approaches to fix your problem.

  1. Initialize a new project based on your exact version of Liferay (and copy your code into the created projects)
  2. Try to fix all dependencies manually

I would suggest to go with 1. as this seems the "cleaner" approach to me. But I will try to explain both ways here as much in detail as I can.


FIRST APPROACH: Initialize a new project

When creating a project with blade, you can give it 2 additional / optional parameters:

--product (dxp | portal - for the community version)
-v (version - like 7.2, 7.3,...)

The whole command for a DXP 7.3 would look like this:

blade create --product dxp -v 7.3 -t rest-builder automapper-service

As for the wizard in Dev Studio, you should be able to select the Liferay Version and the Flavor as well for your project - if you use a Liferay Workspace usually you select it once for the workspace. DevStudio writes this information in your gradle.build of the workspace, so you can change it afterwards, its the liferay.workspace.product and liferay.workspace.target.platform.version variables.

Please have a look here for an exact walkthrough for creating a project in dev studio.


SECOND APPROACH: Manually updating the dependencies

Your package needs the Vulcan API as dependency. And as the deployment in 7.4 works, you seem to compile it for the 7.4 version.

So I would do following approach:

1 Check which version of Vulcan API Liferay is running in your desired Liferay

Startup a Liferay server.

Goto its Gogo Shell and execute:

lb vulcan

You should get some entries back, the correct one is the "Liferay Portal Vulcan API", in my case (DXP 7.3 SP3) it has the version 7.19.2

So you should remember / note that version.

2 Replace all occurences of that dependency in your gradle files

Liferay has an article here which explains more in detail on how to resolve bundle dependencies

Search in Dev Studio via Search -> File for com.liferay.portal.vulcan.api

For example in your build.gradle you will have something like this

    compileOnly group: "com.liferay", name: "com.liferay.portal.vulcan.api", version: "9.3.1"

Update the version to your target version and save the file, so in my case it would look like:

    compileOnly group: "com.liferay", name: "com.liferay.portal.vulcan.api", version: "7.19.2"

One note of warning for this approach: There might be further issues with other dependencies as well. You will have to resolve all of them to successfully deploy to your desired Liferay version. Good thing though, you can do it the same way I described above.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Manuel Manhart