未解决的要求:导入包:com.google.common.base
Unresolved requirement: Import-Package: com.google.common.base
我正在尝试将外部库添加到 Liferay - Orika 库。
我在 build.gradle 中添加了 Gradle 依赖项,如下所示:
compileInclude group: 'ma.glasnost.orika', name: 'orika-core', version: '1.5.4'
我正在使用 compile Include 以便模块也具有附加到它的依赖项。
该库在本地运行良好 - 我已经使用 class 中的主要方法对其进行了测试,但是当我部署到 Portal 时,我收到以下错误:
org.osgi.framework.BundleException: Could not resolve module: <YourModuleName> [2755]_ Unresolved requirement: Import-Package: com.google.common.base_ [Sanitized]
这似乎是由于 运行 时缺少库引起的,但不太清楚的是,如果我 运行 在 [=14] 内添加这些依赖项,为什么会在构建时添加这些依赖项=] 它按预期工作吗?
另外,我检查了我的 Eclipse 中下载的库 Gradle 以查看是否有包含 com.google.commom.base
的软件包,我发现 none.
所以,因为在构建时完成了一些其他步骤,我检查了生成的 jar 中的 MANIFEST.MF(例如 eclipse-workspace\modules\build\libs),然后从文件中删除条目 com.google.commom.base
。错误消失了,但又出现了一个错误:
org.osgi.framework.BundleException: Could not resolve module: <your_module_name> [2755]_ Unresolved requirement: Import-Package: com.sun.jdi_ [Sanitized]
所以,问题是 - 为什么要添加这些依赖项以及如何删除或满足它们? - 考虑到我在 Eclipse 中没有它们,那么我会放弃它们。
这是我花了几个小时得出的结论:
对于外部 jar,compileInclude
策略没有像我预期的那样运行 - 可能是一个很好的引导,但我按照下面详述的步骤进行了。
在我的情况下,在包含依赖项时仅使用 compileOnly
更好。
因此,第一步 - 将以下内容添加到您的 build.gradle
:
compileOnly group: 'ma.glasnost.orika', name: 'orika-core', version: '1.5.4'
在第二步中,您必须在bnd.bnd
文件中指明外部jar需要的其他依赖项。在我的例子中(Orika lib)它需要以下列表: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 - 我检查了 repo详细信息以便找到它并从那里获取信息(例如:来自 here)。所以,在添加到 build.gradle
之后我必须做的是在 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
最后一步是排除构建过程放置在 MANIFEST.MF
文件中的包 - 我在这里谈论的是 Unresolved requirement ...
开头的问题。为了知道不需要什么,我部署了多次,每次我都将所需的包添加到 Import-Package
列表中(这是 bnd.bnd
文件中的另一个 属性) .最终名单是:
Import-Package: \
!com.sun.jdi.*,\
!com.sun.tools.attach,\
!com.google.common.base,\
!org.slf4j.impl,\
*
我正在尝试将外部库添加到 Liferay - Orika 库。
我在 build.gradle 中添加了 Gradle 依赖项,如下所示:
compileInclude group: 'ma.glasnost.orika', name: 'orika-core', version: '1.5.4'
我正在使用 compile Include 以便模块也具有附加到它的依赖项。
该库在本地运行良好 - 我已经使用 class 中的主要方法对其进行了测试,但是当我部署到 Portal 时,我收到以下错误:
org.osgi.framework.BundleException: Could not resolve module: <YourModuleName> [2755]_ Unresolved requirement: Import-Package: com.google.common.base_ [Sanitized]
这似乎是由于 运行 时缺少库引起的,但不太清楚的是,如果我 运行 在 [=14] 内添加这些依赖项,为什么会在构建时添加这些依赖项=] 它按预期工作吗?
另外,我检查了我的 Eclipse 中下载的库 Gradle 以查看是否有包含 com.google.commom.base
的软件包,我发现 none.
所以,因为在构建时完成了一些其他步骤,我检查了生成的 jar 中的 MANIFEST.MF(例如 eclipse-workspacecom.google.commom.base
。错误消失了,但又出现了一个错误:
org.osgi.framework.BundleException: Could not resolve module: <your_module_name> [2755]_ Unresolved requirement: Import-Package: com.sun.jdi_ [Sanitized]
所以,问题是 - 为什么要添加这些依赖项以及如何删除或满足它们? - 考虑到我在 Eclipse 中没有它们,那么我会放弃它们。
这是我花了几个小时得出的结论:
对于外部 jar,compileInclude
策略没有像我预期的那样运行 - 可能是一个很好的引导,但我按照下面详述的步骤进行了。
在我的情况下,在包含依赖项时仅使用 compileOnly
更好。
因此,第一步 - 将以下内容添加到您的 build.gradle
:
compileOnly group: 'ma.glasnost.orika', name: 'orika-core', version: '1.5.4'
在第二步中,您必须在bnd.bnd
文件中指明外部jar需要的其他依赖项。在我的例子中(Orika lib)它需要以下列表: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 - 我检查了 repo详细信息以便找到它并从那里获取信息(例如:来自 here)。所以,在添加到 build.gradle
之后我必须做的是在 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
最后一步是排除构建过程放置在 MANIFEST.MF
文件中的包 - 我在这里谈论的是 Unresolved requirement ...
开头的问题。为了知道不需要什么,我部署了多次,每次我都将所需的包添加到 Import-Package
列表中(这是 bnd.bnd
文件中的另一个 属性) .最终名单是:
Import-Package: \
!com.sun.jdi.*,\
!com.sun.tools.attach,\
!com.google.common.base,\
!org.slf4j.impl,\
*