【发布时间】:2018-08-20 16:23:37
【问题描述】:
我尝试为 android 构建 React Native 应用程序,但在我的企业中,外部存储库被阻止(不允许外部网络)。
所以我们使用内部 maven 存储库来获取工件。
但是我在构建 react native 应用程序时遇到了一些问题,因为具有节点模块依赖项的项目具有要构建的本地 android 代码,该代码引用 jcenter() 存储库(我不想覆盖 node_modules/react*/android/build.gradle手动)。
那么有办法用 gradle 覆盖 jcenter URL 吗?
我在我的用户主页中尝试了init scriptinit.gradle(灵感来自 doc):
apply plugin:EnterpriseRepositoryPlugin
class EnterpriseRepositoryPlugin implements Plugin<Gradle> {
private static String ENTERPRISE_REPOSITORY_URL = "https://my.enterprise.repo"
void apply(Gradle gradle) {
// ONLY USE ENTERPRISE REPO FOR DEPENDENCIES
gradle.allprojects{ project ->
project.repositories {
// Remove all repositories not pointing to the enterprise repository url
all { ArtifactRepository repo ->
project.logger.lifecycle "DEBUG : Repository ${repo.url}"
if (!(repo instanceof MavenArtifactRepository) ||
repo.url.toString() != ENTERPRISE_REPOSITORY_URL) {
project.logger.lifecycle "Repository ${repo.url} removed. Only $ENTERPRISE_REPOSITORY_URL is allowed"
remove repo
}
}
// add the enterprise repository
jcenter {
name "BintrayJCenter"
url ENTERPRISE_REPOSITORY_URL
}
}
}
}
}
但是当我启动 gradlew 时,我得到了这个输出:
DEBUG : Repository https://my.enterprise.repo
DEBUG : Repository https://my.enterprise.repo
DEBUG : Repository https://my.enterprise.repo
DEBUG : Repository https://my.enterprise.repo
DEBUG : Repository https://my.enterprise.repo
DEBUG : Repository https://my.enterprise.repo
DEBUG : Repository https://my.enterprise.repo
FAILURE: Build failed with an exception.
* What went wrong:
A problem occurred configuring root project 'AppliTest'.
> Could not resolve all dependencies for configuration ':classpath'.
> Could not resolve com.android.tools.build:gradle:2.2.3.
Required by:
:AppliLabChatbot:unspecified
> Could not resolve com.android.tools.build:gradle:2.2.3.
> Could not get resource 'https://repo1.maven.org/maven2/com/android/tools/build/gradle/2.2.3/gradle-2.2.3.pom'.
> Could not HEAD 'https://repo1.maven.org/maven2/com/android/tools/build/gradle/2.2.3/gradle-2.2.3.pom'.
> repo1.maven.org
> Could not resolve com.android.tools.build:gradle:2.2.3.
> Could not get resource 'https://jcenter.bintray.com/com/android/tools/build/gradle/2.2.3/gradle-2.2.3.pom'.
> Could not HEAD 'https://jcenter.bintray.com/com/android/tools/build/gradle/2.2.3/gradle-2.2.3.pom'.
> jcenter.bintray.com
> Could not resolve de.undercouch:gradle-download-task:3.1.2.
Required by:
:AppliLabChatbot:unspecified
> Could not resolve de.undercouch:gradle-download-task:3.1.2.
> Could not get resource 'https://repo1.maven.org/maven2/de/undercouch/gradle-download-task/3.1.2/gradle-download-task-3.1.2.pom'.
> Could not HEAD 'https://repo1.maven.org/maven2/de/undercouch/gradle-download-task/3.1.2/gradle-download-task-3.1.2.pom'.
> repo1.maven.org
> Could not resolve de.undercouch:gradle-download-task:3.1.2.
> Could not get resource 'https://jcenter.bintray.com/de/undercouch/gradle-download-task/3.1.2/gradle-download-task-3.1.2.pom'.
> Could not HEAD 'https://jcenter.bintray.com/de/undercouch/gradle-download-task/3.1.2/gradle-download-task-3.1.2.pom'.
> jcenter.bintray.com
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
BUILD FAILED
插件似乎没有拦截 jcenter 存储库...
【问题讨论】:
标签: android react-native gradle gradlew jcenter