You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Liferay 7.3中使用Microsoft Graph发邮件遇依赖解析失败问题

Liferay 7.3 切换Microsoft Graph发送邮件OSGi部署依赖缺失问题解决

问题概述

原Liferay 7.3应用通过JavaMail(SMTP)中继Exchange 365发送邮件,切换为Microsoft Graph方案后,代码编译、Gradle构建均正常,但OSGi部署时报错:

org.osgi.framework.BundleException: Could not resolve module: org.bsfinternational.dashboard [1147]_ Unresolved requirement: Import-Package: com.azure.core.credential_ [Sanitized]

使用的Gradle依赖配置:

// Azure core
implementation 'com.azure:azure-core:1.43.0'
implementation 'com.azure:azure-core-http-netty:1.15.0'
// Include the sdk as a dependency
implementation  'com.microsoft.graph:microsoft-graph:5.57.0'
implementation  'com.microsoft.graph:microsoft-graph-auth:0.3.0'
// Include Azure identity for authentication
implementation 'com.azure:azure-identity:1.9.0'

已尝试调整依赖版本、修改bnd.bnd文件,GoGo Shell未提供有效线索,推测遗漏传递依赖但未找到对应文档说明。

解决方法

1. 处理非OSGi原生依赖

Microsoft Graph和Azure SDK的部分依赖并非原生OSGi bundle,需选择以下方式处理:

  • 将非OSGi依赖改为compileOnly引入,同时通过bnd配置把这些依赖打包进自身bundle
  • 查找并引入对应依赖的OSGi化版本(若存在)

2. 调整bnd.bnd配置

在bnd.bnd中添加配置,确保com.azure.core.credential等包被正确识别和打包:

# 强制导入所需包
Import-Package: com.azure.core.credential,*
# 指定bundle类路径,包含依赖jar
Bundle-ClassPath: .,lib/azure-core-1.43.0.jar,lib/azure-identity-1.9.0.jar,lib/microsoft-graph-5.57.0.jar,lib/microsoft-graph-auth-0.3.0.jar,lib/azure-core-http-netty-1.15.0.jar
# 引入依赖资源,路径需匹配Gradle下载的依赖位置
Include-Resource: lib/azure-core-1.43.0.jar=../.gradle/caches/modules-2/files-2.1/com.azure/azure-core/1.43.0/[具体哈希值]/azure-core-1.43.0.jar,
 lib/azure-identity-1.9.0.jar=../.gradle/caches/modules-2/files-2.1/com.azure/azure-identity/1.9.0/[具体哈希值]/azure-identity-1.9.0.jar,
 lib/microsoft-graph-5.57.0.jar=../.gradle/caches/modules-2/files-2.1/com.microsoft.graph/microsoft-graph/5.57.0/[具体哈希值]/microsoft-graph-5.57.0.jar,
 lib/microsoft-graph-auth-0.3.0.jar=../.gradle/caches/modules-2/files-2.1/com.microsoft.graph/microsoft-graph-auth/0.3.0/[具体哈希值]/microsoft-graph-auth-0.3.0.jar,
 lib/azure-core-http-netty-1.15.0.jar=../.gradle/caches/modules-2/files-2.1/com.azure/azure-core-http-netty/1.15.0/[具体哈希值]/azure-core-http-netty-1.15.0.jar

注:需替换[具体哈希值]为本地Gradle缓存中对应jar的实际哈希目录名。

3. 配置Gradle OSGi插件

确保Gradle构建时正确生成OSGi兼容的manifest,添加插件并配置:

plugins {
    id 'java'
    id 'osgi'
}

jar {
    manifest {
        attributes(
            'Bundle-SymbolicName': 'org.bsfinternational.dashboard',
            'Bundle-Version': '1.0.0',
            'Import-Package': 'com.azure.core.credential,*',
            'Export-Package': 'org.bsfinternational.dashboard.*'
        )
    }
}

4. 检查依赖树并补全缺失包

执行Gradle命令查看完整依赖树,确认com.azure.core.credential所属的依赖是否被正确引入:

./gradlew dependencies

若发现azure-core依赖未被正确包含,需确保其在Gradle配置中被正确声明并下载。

内容的提问来源于stack exchange,提问作者Pete Helgren

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.15 21:53:09