Capacitor 4 Android构建受阻:intellij-core依赖被防火墙拦截求解决
解决Capacitor 4 Android构建时intellij-core依赖被防火墙拦截的问题
问题描述
公司网络通过Nexus防火墙管控仓库访问,intellij-core:30.2.1因存在安全漏洞被拦截,导致Capacitor相关的extractReleaseAnnotations任务执行失败,报错403 Forbidden。涉及的任务包括:
- capacitor-filesystem:extractReleaseAnnotations
- capacitor-splash-screen:extractReleaseAnnotations
- capacitor-cordova-android-plugins:extractReleaseAnnotations
- capacitor-camera:extractReleaseAnnotations
- capacitor-android:extractReleaseAnnotations
控制台报错示例:
5: Task failed with an exception. ----------- * What went wrong: Execution failed for task ':capacitor-android:extractReleaseAnnotations'. > Could not resolve all files for configuration ':capacitor-android:detachedConfiguration2'. > Could not download intellij-core-30.2.1.jar (com.android.tools.external.com-intellij:intellij-core:30.2.1) > Could not get resource 'https://si-devops-mirror.****.fr/repository/dl.google.com/com/android/tools/external/com-intellij/intellij-core/30.2.1/intellij-core-30.2.1.jar'. > Could not HEAD 'https://si-devops-mirror.****.fr/repository/dl.google.com/com/android/tools/external/com-intellij/intellij-core/30.2.1/intellij-core-30.2.1.jar'. > 403 forbidden
尝试在app模块的build.gradle中排除该依赖无效,已知intellij-core:31.0.0-alpha8版本可通过防火墙,需要找到强制替换版本或绕过该依赖的方法。
解决方案
1. 全局强制替换依赖版本(推荐)
在项目根目录的build.gradle中配置版本强制替换,覆盖所有模块对该依赖的版本请求:
Gradle 7+ 推荐写法(使用dependencyResolutionManagement)
dependencyResolutionManagement { resolutionStrategy { eachDependency { details -> if (details.requested.group == 'com.android.tools.external.com-intellij' && details.requested.name == 'intellij-core') { details.useVersion '31.0.0-alpha8' } } } }
兼容旧版Gradle写法
allprojects { repositories { // 保留原有仓库配置 } configurations.all { resolutionStrategy { force 'com.android.tools.external.com-intellij:intellij-core:31.0.0-alpha8' } } }
2. 仅针对Capacitor模块替换版本
如果不想全局修改,可只对Capacitor相关模块生效:
subprojects { if (name.startsWith('capacitor-')) { configurations.all { resolutionStrategy { force 'com.android.tools.external.com-intellij:intellij-core:31.0.0-alpha8' } } } }
3. 禁用extractReleaseAnnotations任务(备选)
如果项目不需要注解提取功能,可直接禁用相关任务:
// 禁用所有Capacitor模块的extractReleaseAnnotations任务 tasks.withType(com.android.build.gradle.tasks.ExtractAnnotations) { enabled = false } // 或者单独禁用指定任务 tasks.named(':capacitor-android:extractReleaseAnnotations').configure { enabled = false } tasks.named(':capacitor-filesystem:extractReleaseAnnotations').configure { enabled = false } tasks.named(':capacitor-splash-screen:extractReleaseAnnotations').configure { enabled = false } tasks.named(':capacitor-cordova-android-plugins:extractReleaseAnnotations').configure { enabled = false } tasks.named(':capacitor-camera:extractReleaseAnnotations').configure { enabled = false }
为什么之前的排除无效?
extractReleaseAnnotations任务使用的是Capacitor模块自身的独立配置(detachedConfiguration),并非从app模块依赖传递而来,因此在app模块的依赖中排除该依赖无法影响Capacitor模块自身的任务配置,必须通过全局或模块级的版本强制替换来解决。
内容的提问来源于stack exchange,提问作者Jonathan Mourier
相关产品推荐
相关产品推荐

