issue with bundling external dependencies in Liferay Dxp bundle

381 views Asked by At

Hi for adding the third party libraries, I followed the article https://dev.liferay.com/develop/tutorials/-/knowledge_base/7-0/adding-third-party-libraries-to-a-module#embedding-libraries-in-a-module. Now the generated bundle has a lib directory with all the dependencies which are configured in the build.gradle. When I deploy the bundle the status of the bundle is installed. When I try to start the bundle I am getting the below error

org.osgi.framework.BundleException: Could not resolve module: com.test..api [564]
  Unresolved requirement: Import-Package: com.ibm.wsdl.extensions.soap

This is not even a transitive dependency for any of my dependency jars that I configured in the build.gradle Can you please help me to resolve this.

2

There are 2 answers

0
Krishna Mohan Mathakala On

Now I am able to start my bundle.

When we configure the dependencies in the build.gradle file and do a gradle refresh, gradle downloads all the dependencies ( including transitive dependencies ). The problem is with these transitive dependencies. Gradle is not downloading all transitive dependencies. It is missing few jars, We have to configure missing jars again in build.gradle and do a gradle refresh.

Work around to find the missing jars :

Configure the dependencies in build.gradle, do a gradle refresh and the deploy. Go to the gogo shell and check for the bundle. Now the bundle will get deployed and will be in installed state. try to start the bundle from gogo shell. Now you will get error similar to Unresolved requirement:Import-Package: com.poi.extractor google the package and try to find out the respective jar in maven repository. Configure the new jar in build.gradle. Continue the same process till the bundle gets activated.

0
ravikuwi On

Add below script in your build.grade to include all the third party dependencies into your OSGi Module, instead of adding them manually one after another.

bundle {
def runtime = project.configurations.runtime
runtime.resolve()
instruction 'Bundle-ClassPath', '.'
instruction 'Bundle-Activator', 'com.XXX.XXXXX.XXXX.ClassName'
runtime.resolvedConfiguration.resolvedArtifacts.each {
    def resrc = it.moduleVersion.id.name + '-' +
            it.moduleVersion.id.version + '.jar'      
    instruction 'Bundle-ClassPath', 'META-INF/lib/' + resrc
    instruction '-includeresource', 'META-INF/lib/' + resrc + '=' + it.file.path
   } 
}