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

标签 gradle osgi portlet liferay-7

我收到这个 Gradle 错误:

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

...对于这个极简主义的 Liferay 7 portlet(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 {
}

在 Debug模式下运行 Gradle 没有给我更多线索:

[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 只有 9 个“不可分配给指定服务”的结果。

我做错了什么?

最佳答案

使用您的源导入:

导入 com.liferay.portal.kernel.model.Portlet;

然后:

@Component( 服务 = Portlet.class )

您断言您的类 MyPortlet 实现了 com.liferay.portal.kernel.model.Portlet。但事实并非如此。 com.liferay.portal.kernel.portlet.bridges.mvc.MVCPortlet 实现 javax.portlet.Portlet

将源导入从 com.liferay.portal.kernel.model.Portlet 更改为 javax.portlet.Portlet

关于Gradle 说 "MyPortlet is not assignable to specified service com.liferay.portal.kernel.model.Portlet",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45918908/

相关文章:

java - jvm添加无参构造函数会破坏OSGi的单例吗?

java - Apache Karaf - 缺少依赖项(看起来是数据源)

testing - 反馈 `test-support`代码的gradle配置

java - 缺少 gradle 2.0.0 beta 7

java - GradlecompileJava任务不断失败

java - RenderRequest 上的协议(protocol)重定向

将 WAR 文件部署到 Liferay 时未创建 SQL 表

java - 如何隐藏我的网址参数?

gradle - 任务不必要地运行

java - 在tomcat中部署后无法访问spring boot应用程序