Search code examples
javaliferayliferay-7

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


The version of this project is 7.2ga1 and I use Liferay Tomcat 7.3.5. I've just tried use the target platform but with no results. Here there are the logs of tomcat, when I deploy the project .

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)
    

This is the code autogenerated when I do the Gradle task buildService

CODE OF Service 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
}
    

This is the code autogenerated when I do the Gradle task buildService

CODE OF 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"
    

CODE OF Service 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`

This is the code autogenerate when I do the Gradle task 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
    
    

So I don t understand why Service can t import package of API.

However see the link below.

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


Solution

  • You start with

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

    and you state that you've tried target platform. In fact, the build dependencies show that you are still using target platform, and most likely your target platform is set to a different version than the runtime you're using: Target Platform should at least match the major/minor part (e.g. 7.3.x), there are different opinions about the depth of it. Simplest: Make your target platform match the version you use at runtime.

    Your service can't import the API bundle, because the API bundle doesn't deploy: It has a dependency on a Liferay kernel that is not there at runtime due to the version mismatch introduced at compile time (through the target platform).

    Set the target platform to 7.3.5, do a clean rebuild and your dependencies should match your runtime version

    Answering your comment: This way you'll have the correct dependency declared in your plugin, and it will be matched at runtime. Your build.gradle doesn't contain any version numbers, because those versions come from the target platform declaration. If you override any dependency's version in bnd.bnd (to 0), the version will be ignored, but there's no guarantee that you have compatible code that indeed can deal with what they find at runtime. Just switching off the correct dependency might work now, but can fail any time that the API you're dependent on is updated with a binary incompatible change.