Gradle says "MyPortlet is not assignable to specified service com.liferay.portal.kernel.model.Portlet"

3.8k Views Asked by At

I get this Gradle error:

> Task :jar
[Class my.MyPortlet is not assignable to specified service com.liferay.portal.kernel.model.Portlet]

... for this minimalist Liferay 7 portlet (a simplification of the official documentation):

package my;

import com.liferay.portal.kernel.model.Portlet;
import com.liferay.portal.kernel.portlet.bridges.mvc.MVCPortlet;
import org.osgi.service.component.annotations.Component;

@Component(
    service = Portlet.class
)
public class MyPortlet extends MVCPortlet {
}

Running Gradle in debug mode does not give me more clues:

[aQute.bnd.osgi.Builder] parseClassFile(): path=javax.portlet.PortletRequest resource=:/home/nico/.gradle/caches/modules-2/files-2.1/javax.portlet/portlet-api/2.0/1cd72f2a37fcf8ab9893a9468d7ba71c85fe2653/portlet-api-2.0.jar(javax/portlet/PortletRequest.class):
[aQute.bnd.osgi.Builder] end
[aQute.bnd.osgi.Builder] begin com.liferay.ant.bnd.npm.NpmAnalyzerPlugin@39735dcf
[aQute.bnd.osgi.Builder] end
[aQute.bnd.osgi.Builder] begin com.liferay.ant.bnd.resource.bundle.ResourceBundleLoaderAnalyzerPlugin@4e811a19
[aQute.bnd.osgi.Builder] end
[aQute.bnd.osgi.Builder] parseClassFile(): path=my/MyPortlet.class resource=/home/nico/my/build/classes/java/main/my/MyPortlet.class
[aQute.bnd.osgi.Builder] begin com.liferay.ant.bnd.sass.SassAnalyzerPlugin@526cd630
[aQute.bnd.osgi.Builder] end
[aQute.bnd.osgi.Builder] begin com.liferay.ant.bnd.service.ServiceAnalyzerPlugin@a73dc4
[aQute.bnd.osgi.Builder] end
[aQute.bnd.osgi.Builder] begin com.liferay.ant.bnd.social.SocialAnalyzerPlugin@2399853a
[aQute.bnd.osgi.Builder] end
[aQute.bnd.osgi.Builder] begin aQute.lib.spring.SpringComponent@650e1282
[aQute.bnd.osgi.Builder] end
[aQute.bnd.osgi.Builder] begin com.liferay.ant.bnd.spring.SpringDependencyAnalyzerPlugin@51e79545
[aQute.bnd.osgi.Builder] end
[aQute.bnd.osgi.Builder] parseClassFile(): path=my/MyPortlet.class resource=/home/nico/my/build/classes/java/main/my/MyPortlet.class
[aQute.bnd.osgi.Verifier] Trying pre-plugin com.liferay.ant.bnd.jsp.JspAnalyzerPlugin
[aQute.bnd.osgi.Verifier] Trying pre-plugin com.liferay.ant.bnd.npm.NpmAnalyzerPlugin
[aQute.bnd.osgi.Verifier] Trying pre-plugin com.liferay.ant.bnd.resource.bundle.ResourceBundleLoaderAnalyzerPlugin
[aQute.bnd.osgi.Verifier] Trying pre-plugin com.liferay.ant.bnd.sass.SassAnalyzerPlugin
[aQute.bnd.osgi.Verifier] Trying pre-plugin com.liferay.ant.bnd.service.ServiceAnalyzerPlugin
[aQute.bnd.osgi.Verifier] Trying pre-plugin com.liferay.ant.bnd.social.SocialAnalyzerPlugin
[aQute.bnd.osgi.Verifier] Trying pre-plugin aQute.lib.spring.SpringComponent
[aQute.bnd.osgi.Verifier] Trying pre-plugin com.liferay.ant.bnd.spring.SpringDependencyAnalyzerPlugin
[org.dm.gradle.plugins.bundle.JarBuilder] [Class my.MyPortlet is not assignable to specified service com.liferay.portal.kernel.model.Portlet]

Google has only 9 results for "is not assignable to specified service".

What am I doing wrong?

2

There are 2 best solutions below

1
On BEST ANSWER

With your source import:

import com.liferay.portal.kernel.model.Portlet;

and then:

@Component( service = Portlet.class )

You are asserting that your class MyPortlet implements com.liferay.portal.kernel.model.Portlet. But it does not. com.liferay.portal.kernel.portlet.bridges.mvc.MVCPortlet implements javax.portlet.Portlet.

Change you source import from com.liferay.portal.kernel.model.Portlet to javax.portlet.Portlet.

0
On

aQute.bnd.component.AnnotationReader tries to parse the service = Portlet.class part and the problem is that aQute.bnd.osgi.Analyzer.assignable(MyPortlet, com.liferay.portal.kernel.model.Portlet) returns false.

Let's follow the class hierarchy:

The portlet implementation in the question

com.liferay.portal.kernel.portlet.bridges.mvc.MVCPortlet

com.liferay.portal.kernel.portlet.LiferayPortlet

javax.portlet.GenericPortlet

javax.portlet.Portlet

This tips us that the import statement is wrong. It should be:

import javax.portlet.Portlet;

... rather than:

import com.liferay.portal.kernel.model.Portlet;

After fixing it, the build is successful.