javadeploymentliferay-7orika

Unresolved requirement: Import-Package: com.google.common.base


I am trying to add an external library to Liferay - the Orika lib.

I have added the Gradle dependency in build.gradle like this:

compileInclude group: 'ma.glasnost.orika', name: 'orika-core', version: '1.5.4'

I am using compile Include in order the module to also have the dependency attached to it.

The lib is working great locally - I have tested it with a main method inside the class, but when I deploy to Portal I receive the following error:

org.osgi.framework.BundleException: Could not resolve module: <YourModuleName> [2755]_  Unresolved requirement: Import-Package: com.google.common.base_ [Sanitized]

This seems to be caused by missing libs at the runtime, but what is not so clear is why are these dependencies added at build time if when I run it within public static main it works as expected ? Also, I have checked the libs Gradle downloaded in my Eclipse to see if there is any package with com.google.commom.base and I found none.

So, because some other step is done when building, I checked the the MANIFEST.MF in the generated jar (eg. eclipse-workspace<your_project_name>\modules<your_module_name>\build\libs) and then removing the entry com.google.commom.base from file. The error dissapeared, but another one occurred:

org.osgi.framework.BundleException: Could not resolve module: <your_module_name> [2755]_  Unresolved requirement: Import-Package: com.sun.jdi_ [Sanitized]

So, the question is - Why are those dependencies added and how can I drop or satisfy them ? - given the fact that I do not have them in Eclipse, then I would go for dropping them.


Solution

  • This is my conclusions after some hours spent with this:

    For external jars, the compileInclude tactic did not behaving as I was expecting - maybe was a good lead, but I went with the steps detailed below.

    In my situation, using only compileOnly when including the dependency was better. So, the first step - add the following to your build.gradle:

    compileOnly group: 'ma.glasnost.orika', name: 'orika-core', version: '1.5.4'
    

    In the second step, you have to indicate in bnd.bnd file the other dependencies the external jar needs. In my case (Orika lib) it needed the following list: commons-compiler-3.0.8.jar,janino-3.0.8.jar,java-sizeof-0.0.5.jar,javassist-3.24.0-GA.jar,paranamer-2.8.jar,@slf4j-api-1.7.26.jar - I have checked the repo details in order to find this out and got the info from there (eg: from here). So, what I had to do after adding to build.gradle was to add the following line in bnd.bnd:

    Include-Resource: @orika-core-1.5.4.jar,@commons-compiler-3.0.8.jar,@janino-3.0.8.jar,@java-sizeof-0.0.5.jar,@javassist-3.24.0-GA.jar,@paranamer-2.8.jar,@slf4j-api-1.7.26.jar
    

    The last step was to exclude the packages the build process is placing in the MANIFEST.MF file - I am talking here about the issues that start with Unresolved requirement .... In order to know what it wasn't needed, I deployed multiple times and for each time I have added the required package to the Import-Package list (this is another property in bnd.bnd file). The final list was:

    Import-Package: \
      !com.sun.jdi.*,\
      !com.sun.tools.attach,\
      !com.google.common.base,\
      !org.slf4j.impl,\
      *
    

    Note: you may find useful to read more about what I have written here and here.