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

AEM无法解析reCAPTCHA Enterprise依赖包问题求助

问题描述

在Captcha Service中导入以下包:

import com.google.cloud.recaptchaenterprise.v1.RecaptchaEnterpriseServiceClient;
import com.google.recaptchaenterprise.v1.Assessment;
import com.google.recaptchaenterprise.v1.CreateAssessmentRequest;
import com.google.recaptchaenterprise.v1.Event;
import com.google.recaptchaenterprise.v1.ProjectName;

但在AEM控制台中始终无法解析com.google.cloud.recaptchaenterprise.v1包,日志错误如下:

12.09.2024 07:16:47.459 *ERROR* [FelixLogListener] Events.Framework.project-www.core FrameworkEvent ERROR (org.apache.felix.log.LogException: org.osgi.framework.BundleException: Unable to resolve project-www.core [606](R 606.248): missing requirement [project-www.core [606](R 606.248)] osgi.wiring.package; (osgi.wiring.package=com.google.cloud.recaptchaenterprise.v1) Unresolved requirements: [[project-www.core [606](R 606.248)] osgi.wiring.package; (osgi.wiring.package=com.google.cloud.recaptchaenterprise.v1)])
org.apache.felix.log.LogException: org.osgi.framework.BundleException: Unable to resolve project-www.core [606](R 606.248): missing requirement [project-www.core [606](R 606.248)] osgi.wiring.package; (osgi.wiring.package=com.google.cloud.recaptchaenterprise.v1) Unresolved requirements: [[project-www.core [606](R 606.248)] osgi.wiring.package; (osgi.wiring.package=com.google.cloud.recaptchaenterprise.v1)]
    at org.apache.felix.framework.Felix.resolveBundleRevision(Felix.java:4398)
    at org.apache.felix.framework.Felix.startBundle(Felix.java:2308)
    at org.apache.felix.framework.Felix.setActiveStartLevel(Felix.java:1566)
    at org.apache.felix.framework.FrameworkStartLevelImpl.run(FrameworkStartLevelImpl.java:308)
    at java.base/java.lang.Thread.run(Thread.java:834)

AEMaaCS构建日志报错:

2024-09-10 02:34:57.644 Analyser errors have been found 
2024-09-10 02:34:57.644 The analyser found the following errors for author and publish : 
2024-09-10 02:34:57.644 [api-regions-exportsimports] my.co.project:project-www.core:0.0.1-SNAPSHOT: Bundle project-www.core:0.0.1-SNAPSHOT is importing package(s) [com.google.cloud.recaptchaenterprise.v1, com.google.recaptchaenterprise.v1] in start level 20 but no bundle is exporting these for that start level. (my.co.project:project-www.ui.apps:0.0.1-SNAPSHOT)

Maven构建正常,当前POM配置:
父pom.xml

<build>
    <plugins>
        ......
        <plugin>
            <!-- Builds the dependency as OSGi bundle -->
            <groupId>org.apache.felix</groupId>
            <artifactId>maven-bundle-plugin</artifactId>
            <extensions>true</extensions>
            <configuration>
                <instructions>
                    <Import-Package>*;resolution:=optional</Import-Package>
                    <Export-Package>
                        com.google.recaptchaenterprise.v1.*,
                        com.google.auth.*,
                        com.google.api.gax.*,
                        com.google.cloud.recaptchaenterprise.v1.*
                    </Export-Package>
                    <Embed-Dependency>*;scope=compile|runtime</Embed-Dependency>
                    <Embed-Transitive>true</Embed-Transitive>
                </instructions>
            </configuration>
        </plugin>
        <plugin>
            <!-- Installs the build OSGi bundle into specified AEM instance's felix console -->
            <groupId>org.apache.sling</groupId>
            <artifactId>sling-maven-plugin</artifactId>
            <executions>
                <execution>
                    <id>install-bundle</id>
                    <goals>
                        <goal>install</goal>
                    </goals>
                    <configuration>
                        <slingUrl>http://${aem.host}:${aem.port}/system/console</slingUrl>
                        <refreshPackages>true</refreshPackages>
                    </configuration>
                </execution>
            </executions>
        </plugin>
        ......
    </plugins>
</build>
<dependency>
    <groupId>com.google.cloud</groupId>
    <artifactId>google-cloud-recaptchaenterprise</artifactId>
    <version>3.18.0</version>
</dependency>

core/pom.xml

<dependency>
    <groupId>com.google.cloud</groupId>
    <artifactId>google-cloud-recaptchaenterprise</artifactId>
</dependency>
解决方案

1. 调整maven-bundle-plugin配置位置

把父pom中的maven-bundle-plugin配置移到core/pom.xml的<build><plugins>节点下,仅让core模块应用该OSGi打包规则,避免影响其他子模块。

2. 优化依赖嵌入规则

不要用*通配符嵌入所有依赖,明确指定只嵌入recaptcha相关包,减少冗余:

<Embed-Dependency>google-cloud-recaptchaenterprise;scope=compile|runtime</Embed-Dependency>

3. 修正导入导出配置

  • 删除<Export-Package>中的Google相关包(除非其他模块需要调用这些API),只导出你自己的业务包:
<Export-Package>
    com.my.project.captcha.* <!-- 替换成你的业务包路径 -->
</Export-Package>
  • 修改<Import-Package>,排除已嵌入的Google包,避免Felix尝试从外部解析:
<Import-Package>
    !com.google.cloud.recaptchaenterprise.v1,
    !com.google.recaptchaenterprise.v1,
    !com.google.auth.*,
    !com.google.api.gax.*,
    *;resolution:=optional
</Import-Package>

4. 兼容AEMaaCS构建分析器

如果仍有api-regions-exportsimports错误,在core/pom.xml中添加aem-maven-plugin配置,告知分析器这些包是内部嵌入的:

<plugin>
    <groupId>com.adobe.aem</groupId>
    <artifactId>aem-maven-plugin</artifactId>
    <configuration>
        <apiRegions>
            <excludes>
                <exclude>com.google.cloud.recaptchaenterprise.v1</exclude>
                <exclude>com.google.recaptchaenterprise.v1</exclude>
                <exclude>com.google.auth.*</exclude>
                <exclude>com.google.api.gax.*</exclude>
            </excludes>
        </apiRegions>
    </configuration>
</plugin>

5. 验证效果

构建完成后,在AEM控制台的Bundle Manager中查看core bundle的内容,确认com.google.cloud.recaptchaenterprise.v1等包已嵌入到bundle内部,再启动bundle验证是否正常。


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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.18 12:13:18