“Unresolved requirement: Import-Package” for a module not in my build.gradle

前端 未结 2 538
失恋的感觉
失恋的感觉 2021-01-24 09:58

I want to use Elasticsearch\'s Client Java class within a Liferay 7 SP4 FP30 module, so I wrote this build.gradle:

dependencies {
    compileOnly gr         


        
相关标签:
2条回答
  • 2021-01-24 10:33

    I'm not familiar with Liferay and gradle, but I've been working with OSGi (apache felix) and maven for a long time. The error message indicates that your bundle uses the package com.liferay.portal.search.elasticsearch.connection, but the runtime environment does not have a bundle that exports that package. The package in question is contained in the first dependency mentioned in your build.gradle, but it's not exported. If you like, you can open the bundle jar and peek into its manifest.mf by downloading it from the maven central repo.

    Since the package is not exported (only com.liferay.portal.search.elasticsearch.settings is), I assume it's a signal that it's not intended for external use. So maybe you should check if there's another way of doing what you want.

    From looking at the Liferay docs for using 3rd party libraries, it seems you are trying to expand the library into your module. Maybe you could try the embedding strategy instead, if you still need to use the .connection package.

    0 讨论(0)
  • 2021-01-24 10:45

    @gjoranv is correct, just because you in is on your gradle.build it does not mean it will be in your environment.

    First things first, the error is due to the lack of a used package, in Java's conventional sense. So you will need a module, as represented by a jar file, that makes this package public.

    As liferay is pretty version dependent when it comes to Elastic Search, and relies on accident versions, you might get away with using not exposed packages, and forcing the exposure, normally through a Uber module.

    If you are feeling lucky, you can also use compileInclude, instead of compileOnly. Including the library this way will possibly make a mess, as it will embed the jar inside your jar and expose all packages.

    Another possibility, which normally is way less aggressive is to embed the jar, and set the classpath inside your bundle. To do this you just need to declare your dependency as compile, and add the classpath in your bnd.bnd file. (it sounds harder than it is, it should be a trivial process)

    Another issue to have in mind is the alignment with your ElasticSearch and you liferay deployment:2.2-2.4.x but this is just because you might fall into class conversion exceptions and API mismatch if your objects are used by other bundles or when interfacing with an old ES.


    Embedding example:

    gradle.build

    compile "org.apache.httpcomponents:httpclient"
    compile "org.apache.httpcomponents:httpcore"
    

    bnd.bnd

    -includeresource: lib/httpclient.jar=httpclient-4.5.3.jar,\
                      lib/httpcore.jar=httpcore-4.4.6.jar
    
    Bundle-ClassPath: ., lib/httpclient.jar, lib/httpcore.jar
    
    0 讨论(0)
提交回复
热议问题