未解决的要求:导入包:com.liferay.docs.guestbook.model;版本="[1.0.0,1.1.0)"_

Unresolved requirement: Import-Package: com.liferay.docs.guestbook.model; version="[1.0.0,1.1.0)"_

这个项目的版本是7.2ga1,我用的是LiferayTomcat7.3.5。 我刚刚尝试使用目标平台但没有结果。 这里有我部署项目时tomcat的日志。

2020-11-23 11:03:21.019 ERROR [fileinstall-C:/java/bundles/liferay-ce-portal-tomcat-7.3.4-ga5-20200811154319029/liferay-ce-portal-7.3.4-ga5/osgi/modules][DirectoryWatcher:1112] Unable to start bundle: file:/C:/java/bundles/liferay-ce-portal-tomcat-7.3.4-ga5-20200811154319029/liferay-ce-portal-7.3.4-ga5/osgi/modules/com.liferay.docs.guestbook.service.jar
    org.osgi.framework.BundleException: **Could not resolve module: com.liferay.docs.guestbook.service [2425]_  Unresolved requirement: Import-Package: com.liferay.docs.guestbook.exception; version="[1.0.0,2.0.0)"_**    -> Export-Package: com.liferay.docs.guestbook.exception; bundle-symbolic-name="com.liferay.docs.guestbook.api"; bundle-version="1.0.0"; version="1.0.0"; uses:="com.liferay.portal.kernel.exception"_       com.liferay.docs.guestbook.api [2423]_         Unresolved requirement: Import-Package: com.liferay.portal.kernel.dao.orm; version="[9.6.0,10.0.0)"_  Unresolved requirement: Import-Package: com.liferay.docs.guestbook.model; version="[1.0.0,1.1.0)"_    -> Export-Package: com.liferay.docs.guestbook.model; bundle-symbolic-name="com.liferay.docs.guestbook.api"; bundle-version="1.0.0"; version="1.0.0"; uses:="com.liferay.exportimport.kernel.lar,com.liferay.portal.kernel.annotation,com.liferay.portal.kernel.bean,com.liferay.portal.kernel.model,com.liferay.portal.kernel.model.wrapper,com.liferay.portal.kernel.util"_ [Sanitized]
  at org.eclipse.osgi.container.Module.start(Module.java:444)
  at org.eclipse.osgi.internal.framework.EquinoxBundle.start(EquinoxBundle.java:428)
  at com.liferay.portal.file.install.internal.DirectoryWatcher._startBundle(DirectoryWatcher.java:1095)
  at com.liferay.portal.file.install.internal.DirectoryWatcher._startBundles(DirectoryWatcher.java:1128)
  at com.liferay.portal.file.install.internal.DirectoryWatcher._startAllBundles(DirectoryWatcher.java:1073)
  at com.liferay.portal.file.install.internal.DirectoryWatcher._process(DirectoryWatcher.java:985)

2020-11-23 11:03:21.022 ERROR [fileinstall-C:/java/bundles/liferay-ce-portal-tomcat-7.3.4-ga5-20200811154319029/liferay-ce-portal-7.3.4-ga5/osgi/modules][DirectoryWatcher:1112] Unable to start bundle: file:/C:/java/bundles/liferay-ce-portal-tomcat-7.3.4-ga5-20200811154319029/liferay-ce-portal-7.3.4-ga5/osgi/modules/com.liferay.docs.guestbook.api.jar
org.osgi.framework.BundleException: Could not resolve module: com.liferay.docs.guestbook.api [2423]_  Unresolved requirement: Import-Package: com.liferay.portal.kernel.dao.orm; version="[9.6.0,10.0.0)"_ [Sanitized]
  at org.eclipse.osgi.container.Module.start(Module.java:444)
  at org.eclipse.osgi.internal.framework.EquinoxBundle.start(EquinoxBundle.java:428)
  at com.liferay.portal.file.install.internal.DirectoryWatcher._startBundle(DirectoryWatcher.java:1095)
  at com.liferay.portal.file.install.internal.DirectoryWatcher._startBundles(DirectoryWatcher.java:1128)
  at com.liferay.portal.file.install.internal.DirectoryWatcher._startAllBundles(DirectoryWatcher.java:1073)
  at com.liferay.portal.file.install.internal.DirectoryWatcher._process(DirectoryWatcher.java:985)
  at com.liferay.portal.file.install.internal.DirectoryWatcher.run(DirectoryWatcher.java:302)
2020-11-23 11:03:21.025 ERROR [fileinstall-C:/java/bundles/liferay-ce-portal-tomcat-7.3.4-ga5-20200811154319029/liferay-ce-portal-7.3.4-ga5/osgi/modules][DirectoryWatcher:1112] Unable to start bundle: file:/C:/java/bundles/liferay-ce-portal-tomcat-7.3.4-ga5-20200811154319029/liferay-ce-portal-7.3.4-ga5/osgi/modules/com.liferay.docs.guestbook.api.jar
org.osgi.framework.BundleException: Could not resolve module: com.liferay.docs.guestbook.api [2423]_  Unresolved requirement: Import-Package: com.liferay.portal.kernel.dao.orm; version="[9.6.0,10.0.0)"_ [Sanitized]
  at org.eclipse.osgi.container.Module.start(Module.java:444)
  at org.eclipse.osgi.internal.framework.EquinoxBundle.start(EquinoxBundle.java:428)
  at com.liferay.portal.file.install.internal.DirectoryWatcher._startBundle(DirectoryWatcher.java:1095)
  at com.liferay.portal.file.install.internal.DirectoryWatcher._startBundles(DirectoryWatcher.java:1128)
  at com.liferay.portal.file.install.internal.DirectoryWatcher._process(DirectoryWatcher.java:990)
  at com.liferay.portal.file.install.internal.DirectoryWatcher.run(DirectoryWatcher.java:302)
    

这是我执行 Gradle 任务 buildService

时自动生成的代码

服务代码build.gradle

dependencies {
    compileOnly project(":modules:guestbook:guestbook-api")
    
    compileOnly group: "com.liferay", name: "com.liferay.petra.io"
    compileOnly group: "com.liferay", name: "com.liferay.petra.lang"
    compileOnly group: "com.liferay", name: "com.liferay.petra.string"
    compileOnly group: "com.liferay", name: "com.liferay.portal.aop.api"
    compileOnly group: "com.liferay.portal", name: "com.liferay.portal.kernel"
    compileOnly group: "org.osgi", name: "org.osgi.annotation.versioning"
    compileOnly group: "org.osgi", name: "org.osgi.core"
    compileOnly group: "org.osgi", name: "org.osgi.service.component.annotations"
    compileOnly group: "com.liferay", name: "com.liferay.petra.sql.dsl.api"
}
    
buildService {
    apiDir = "../guestbook-api/src/main/java"
}
    
group = "com.liferay.docs.guestbook"
    
tasks.withType(JavaCompile) {
    
    // Generated classes using Jodd library are unable to be read when compiled against JDK 11
    
    sourceCompatibility = JavaVersion.VERSION_1_8
    targetCompatibility = JavaVersion.VERSION_1_8
}
    

这是我执行 Gradle 任务 buildService

时自动生成的代码

代码 api build.gradle

dependencies {
    compileOnly group: "com.liferay", name: "com.liferay.petra.lang"
    compileOnly group: "com.liferay", name: "com.liferay.petra.string"
    compileOnly group: "com.liferay.portal", name: "com.liferay.portal.kernel"
    compileOnly group: "org.osgi", name: "org.osgi.annotation.versioning"
    compileOnly group: "org.osgi", name: "org.osgi.core"
    compileOnly group: "org.osgi", name: "org.osgi.service.component.annotations"
    compileOnly group: "com.liferay", name: "com.liferay.petra.sql.dsl.api"
    

服务代码bnd.bnd

Bundle-Name: guestbook-service
Bundle-SymbolicName: com.liferay.docs.guestbook.service
Bundle-Version: 1.0.0
Liferay-Require-SchemaVersion: 1.0.0
Liferay-Service: true
-dsannotations-options: inherit`

这是我执行 Gradle 任务 buildService

时自动生成的代码
    **CODE OF Api bdn.bdn** 
    
Bundle-Name: guestbook-api
Bundle-SymbolicName: com.liferay.docs.guestbook.api
Bundle-Version: 1.0.0
Export-Package:\
  com.liferay.docs.guestbook.exception,\
  com.liferay.docs.guestbook.model,\
  com.liferay.docs.guestbook.service,\
  com.liferay.docs.guestbook.service.persistence
-check: EXPORTS
-includeresource: META-INF/service.xml=../guestbook-service/service.xml
    
    

所以我不明白为什么Service无法导入API的包。

但是请参阅下面的 link。

This is the project that Liferay makes you do if you are a principiant, and Im following this

你开始于

The version of this project is 7.2ga1 and I use Liferay Tomcat 7.3.5

并且您声明您已经尝试过目标平台。事实上,构建依赖项表明您仍在使用目标平台,并且很可能您的目标平台设置为与您正在使用的运行时不同的版本:目标平台应该至少匹配 major/minor 部分(例如7.3.x),关于它的深浅,众说纷纭。最简单:使您的目标平台与您在运行时使用的版本相匹配。

您的服务无法导入 API 包,因为 API 包未部署:它依赖于 Liferay 内核,由于版本原因,该内核在运行时不存在编译时引入的不匹配(通过目标平台)。

将目标平台设置为 7.3.5,进行全新重建,您的依赖项应与您的运行时版本相匹配

回答您的评论:这样您就可以在插件中声明正确的依赖项,并在运行时进行匹配。您的 build.gradle 不包含任何版本号,因为这些版本来自目标平台声明。如果您在 bnd.bnd 中覆盖任何依赖项的版本(至 0),该版本将被忽略,但不能保证您拥有确实可以处理它们在运行时发现的内容的兼容代码。只需关闭正确的依赖关系 可能 现在可以工作,但任何时候你所依赖的 API 更新为二进制不兼容的更改都可能失败。