"error: cannot find symbol import com.liferay.portal.kernel.uuid.PortalUUID;" in Liferay 7.4

123 views Asked by At

I am working with Liferay portal-7.4-ga107 (with IntelliJ) and trying to do a training guestbook app following this tutorial from Liferay. I have followed it perfectly and even repeated the process 3 times, but at the end of the "Integrating the Back-end" step I always encounter this error right after deploying the module/portlet:

error: cannot find symbol
import com.liferay.portal.kernel.uuid.PortalUUID;
                                     ^
  symbol:   class PortalUUID
  location: package com.liferay.portal.kernel.uuid

The error seems to be directly related to this dependency in the persistence classes (which are auto-generated in the process):

import com.liferay.portal.kernel.uuid.PortalUUID; //(highlighted as red in code)

Inside the persistence classes, PortalUUID is only "used" here:

    @Reference
    private PortalUUID _portalUUID;

and here:

    String uuid = _portalUUID.generate();

I've done a lot of research and tried a few things, with no luck. The error could be related to something that is outdated and I haven't found, or a change in PortalUUID for my version, I really don't know.

I'm using JDK 8 and gradle 6.9.2

Any help is appreciated, thanks in advance.

Relevant attempts:

I tried to deploy my portlet guestbook-web after finishing this step from the Liferay tutorial, I expected it to get built successfully, but the kernel.uuid.PortalUUID dependency error appeared.

Afterwards, I tried replacing PortalUUID with PortalUUIDUtil, this last one didn't cause any errors in the code, but after deploying the module (guestbook-web), it didn't appear in the portal.

Finally, I saw in Liferay docs that PortalUUIDUtil has a getPortalUUID() method, I tried using PortalUUIDUtil.getPortalUUID(); with no luck (the method doesn't even exist according to my IDE).

2

There are 2 answers

12
SilverSurfer On BEST ANSWER

Liferay 7.4 (after GA/U 100) requires the workspace version 9.0.4 or higher to generate ServiceBuilder code adapted to the changed PortalUUID API.

Make sure to configure your Liferay workspace at least like this in your settings.gradle:

dependencies {   
    classpath group: “com.liferay”, 
              name: “com.liferay.gradle.plugins.workspace”, 
              version: “9.0.4"
}
0
Olaf Kock On

The implementation (and API) seems to have changed recently, and the tutorial isn't updated yet.

Best bet is the current PortalUUIDUtil class, that uses java.util.UUID in its generate method.

I'd expect PortalUUIDUtil.generate() to be the new replacement. Use with a grain of salt: This is only from looking at the implementation, not at the tutorial/sample code.

And, as pointed out in a comment for another answer: It seems that the use within Liferay ServiceBuilder requires newer ServiceBuilder implementations, so you'll need to run it within a newer Liferay Workspace, starting with version 9. The difference to the paragraphs above this is: ServiceBuilder is generating this code for you, and it has been adapted to the API change. With the proper Workspace version, you'll likely never see this issue, because the generated code already includes the necessary API change.