RE: Service-Builder error because of Import-Package missing

Alex Pasquini, modified 5 Years ago. Junior Member Posts: 38 Join Date: 3/3/20 Recent Posts
Dear all,

I'm trying to develop a dummy service just to try the service builder feature. My environment is composed by Liferay 7.3 ga1 for Presentation and Business Layer with MySql db as my Persistence Layer.
I followed the steps included on Liferay tutorial, in particular I try to describe below what I've done:
1. I created a new Module Project called "MyServiceTest"

2. I've defined the package name as "com.test"

3. I ran with success the buildService function of the module project

4. After updating the Gradle Project, I was able to see that classes were correctly generated

5. I ran the deploy gradle task with success

6. Then I paste the generated jar on deploy folder of Liferay
7. I receive the following log
2020-03-21 14:53:31.786 INFO  [com.liferay.portal.kernel.deploy.auto.AutoDeployScanner][AutoDeployDir:263] Processing com.test.api.jar
2020-03-21 14:53:31.847 INFO  [com.liferay.portal.kernel.deploy.auto.AutoDeployScanner][AutoDeployDir:263] Processing com.test.service.jar
2020-03-21 14:53:40.376 ERROR [fileinstall-/Users/admin/Documents/Liferay 7.3 ga1/Infrastruttura/Portal Server/liferay-ce-portal-7.3.0-ga1/osgi/modules][LogService:93] Error while starting bundle: file:/Users/admin/Documents/Liferay%207.3%20ga1/Infrastruttura/Portal%20Server/liferay-ce-portal-7.3.0-ga1/osgi/modules/com.test.api.jar
org.osgi.framework.BundleException: Could not resolve module: com.test.api [1132]_  Unresolved requirement: Import-Package: com.liferay.exportimport.kernel.lar; version="[2.4.0,3.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 org.apache.felix.fileinstall.internal.DirectoryWatcher.startBundle(DirectoryWatcher.java:1297)
    at org.apache.felix.fileinstall.internal.DirectoryWatcher.startBundles(DirectoryWatcher.java:1270)
    at org.apache.felix.fileinstall.internal.DirectoryWatcher.startAllBundles(DirectoryWatcher.java:1259)
    at org.apache.felix.fileinstall.internal.DirectoryWatcher.doProcess(DirectoryWatcher.java:519)
    at org.apache.felix.fileinstall.internal.DirectoryWatcher.process(DirectoryWatcher.java:369)
    at org.apache.felix.fileinstall.internal.DirectoryWatcher.run(DirectoryWatcher.java:320)
2020-03-21 14:53:40.412 ERROR [fileinstall-/Users/admin/Documents/Liferay 7.3 ga1/Infrastruttura/Portal Server/liferay-ce-portal-7.3.0-ga1/osgi/modules][LogService:93] Error while starting bundle: file:/Users/admin/Documents/Liferay%207.3%20ga1/Infrastruttura/Portal%20Server/liferay-ce-portal-7.3.0-ga1/osgi/modules/com.test.service.jar
org.osgi.framework.BundleException: Could not resolve module: com.test.service [1134]_  Unresolved requirement: Import-Package: com.liferay.asset.kernel.service; version="[1.12.0,2.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 org.apache.felix.fileinstall.internal.DirectoryWatcher.startBundle(DirectoryWatcher.java:1297)
    at org.apache.felix.fileinstall.internal.DirectoryWatcher.startBundles(DirectoryWatcher.java:1270)
    at org.apache.felix.fileinstall.internal.DirectoryWatcher.startAllBundles(DirectoryWatcher.java:1259)
    at org.apache.felix.fileinstall.internal.DirectoryWatcher.doProcess(DirectoryWatcher.java:519)
    at org.apache.felix.fileinstall.internal.DirectoryWatcher.process(DirectoryWatcher.java:369)
    at org.apache.felix.fileinstall.internal.DirectoryWatcher.run(DirectoryWatcher.java:320)
2020-03-21 14:53:40.418 ERROR [fileinstall-/Users/admin/Documents/Liferay 7.3 ga1/Infrastruttura/Portal Server/liferay-ce-portal-7.3.0-ga1/osgi/modules][LogService:93] Error while starting bundle: file:/Users/admin/Documents/Liferay%207.3%20ga1/Infrastruttura/Portal%20Server/liferay-ce-portal-7.3.0-ga1/osgi/modules/com.test.service.jar
org.osgi.framework.BundleException: Could not resolve module: com.test.service [1134]_  Unresolved requirement: Import-Package: com.liferay.asset.kernel.service; version="[1.12.0,2.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 org.apache.felix.fileinstall.internal.DirectoryWatcher.startBundle(DirectoryWatcher.java:1297)
    at org.apache.felix.fileinstall.internal.DirectoryWatcher.startBundles(DirectoryWatcher.java:1270)
    at org.apache.felix.fileinstall.internal.DirectoryWatcher.doProcess(DirectoryWatcher.java:524)
    at org.apache.felix.fileinstall.internal.DirectoryWatcher.process(DirectoryWatcher.java:369)
    at org.apache.felix.fileinstall.internal.DirectoryWatcher.run(DirectoryWatcher.java:320)
2020-03-21 14:53:40.428 ERROR [fileinstall-/Users/admin/Documents/Liferay 7.3 ga1/Infrastruttura/Portal Server/liferay-ce-portal-7.3.0-ga1/osgi/modules][LogService:93] Error while starting bundle: file:/Users/admin/Documents/Liferay%207.3%20ga1/Infrastruttura/Portal%20Server/liferay-ce-portal-7.3.0-ga1/osgi/modules/com.test.api.jar
org.osgi.framework.BundleException: Could not resolve module: com.test.api [1132]_  Unresolved requirement: Import-Package: com.liferay.exportimport.kernel.lar; version="[2.4.0,3.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 org.apache.felix.fileinstall.internal.DirectoryWatcher.startBundle(DirectoryWatcher.java:1297)
    at org.apache.felix.fileinstall.internal.DirectoryWatcher.startBundles(DirectoryWatcher.java:1270)
    at org.apache.felix.fileinstall.internal.DirectoryWatcher.doProcess(DirectoryWatcher.java:524)
    at org.apache.felix.fileinstall.internal.DirectoryWatcher.process(DirectoryWatcher.java:369)
    at org.apache.felix.fileinstall.internal.DirectoryWatcher.run(DirectoryWatcher.java:320)

In conclusion I describe the api and service build.gradle and bnd.bnd
1. *-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"
}
2. *-api/bnd.bnd
Bundle-Name: MyTestService-api
Bundle-SymbolicName: com.test.api
Bundle-Version: 1.0.0
Export-Package:\
    com.test.exception,\
    com.test.model,\
    com.test.service,\
    com.test.service.persistence
-check: EXPORTS
-includeresource: META-INF/service.xml=../MyTestService-service/service.xml
3. *-service/build.gradle
dependencies {
    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 project(":modules:MyTestService:MyTestService-api")
}
buildService {
    apiDir = "../MyTestService-api/src/main/java"
}
group = "com.test"
4. *-service/bnd.bnd
Bundle-Name: MyTestService-service
Bundle-SymbolicName: com.test.service
Bundle-Version: 1.0.0
Liferay-Require-SchemaVersion: 1.0.0
Liferay-Service: true
-dsannotations-options: inherit
Can you please give me support?
Thank you.
Best regards,

Alex
thumbnail
Minhchau Dang, modified 5 Years ago. Liferay Master Posts: 598 Join Date: 10/22/07 Recent Posts
Unresolved requirement: Import-Package: com.liferay.exportimport.kernel.lar; version="[2.4.0,3.0.0)"

Looks like you're compiling against a 7.2 version of portal-kernel instead of a 7.3 version of portal-kernel.

  • If you're using BOMs, have up updated it to point to the 7.3 release BOM?
  • If you're not using BOMs, what version of com.liferay.portal.kernel does your build.gradle point to? 7.3.0 released with version 5.4.0 of com.liferay.portal.kernel.
Alex Pasquini, modified 5 Years ago. Junior Member Posts: 38 Join Date: 3/3/20 Recent Posts
Hi Minhchau,

thank you for replying.
Actually I don't have any bom reference on build.gradle file on my parent project and I haven't set this dependency in any file.
What is the correct configuration? Should I specify the dependency on the build.gradle file on my parent project?
Just for describe the project status I've the following file:
  • Workspace
    • MyServiceTest
      • MyServiceTest-api (build.gradle already reported in my previous post)
      • MyServiceTest-service (build.gradle already reported in my previous post)
      • build.gradle --> empty (build.gradle of my parent project)
    • build.gradle --> empty (build.gradle of my workspace)
    • settings.gradle  (settings of my workspace, reported below)
This is the content of settings.gradle of my workspace:

buildscript {
    dependencies {
        classpath group: "com.liferay", name: "com.liferay.gradle.plugins.workspace", version: "2.2.6"
        classpath group: "net.saliman", name: "gradle-properties-plugin", version: "1.4.6"
    }
    repositories {
        maven {
            url "https://repository-cdn.liferay.com/nexus/content/groups/public"
        }
    }
}
apply plugin: "net.saliman.properties"
apply plugin: "com.liferay.workspace"

Thank you in advance.
Best regards,

Alex
Alex Pasquini, modified 5 Years ago. Junior Member Posts: 38 Join Date: 3/3/20 Recent Posts
Morover I've seen in maven repository that there is not bom for liferay ce 7.3 ga1 as illustrated below https://mvnrepository.com/artifact/com.liferay/com.liferay.ce.portal.bom

I've also checked this library, anyway I don't know if it fits for my case https://mvnrepository.com/artifact/com.liferay.portal/release.portal.bom/7.3.0

Thank you in advance.
Best regards,

Alex
thumbnail
Olaf Kock, modified 5 Years ago. Liferay Legend Posts: 6441 Join Date: 9/23/08 Recent Posts
Try your Liferay Workspace's gradle.properties (top level) and the value you find there for liferay.workspace.target.platform.version
Alex Pasquini, modified 5 Years ago. Junior Member Posts: 38 Join Date: 3/3/20 Recent Posts
It seems I've imported an old workspace with 7.2 version.
Thank you all for your support.
Best regards,

Alex