[英]gradlew change jcenter() URL for React Native build
I trying to build a React Native application for android but in my enterprise, external repositories are blocked (external network not allowed). 我试图为Android构建React Native应用程序,但是在我的企业中,外部存储库被阻止(不允许外部网络)。
So we use an internal maven repository to get artifacts. 因此,我们使用内部Maven存储库来获取工件。 But I encountered some problems to build a react native application because the project with node modules dependencies, have native android code to build that refers to
jcenter()
repository (I don't want to override node_modules/react*/android/build.gradle manually). 但是我在构建
jcenter()
Native应用程序时遇到了一些问题,因为具有节点模块依赖项的项目具有要引用jcenter()
存储库的本机android代码来构建(我不想覆盖node_modules / react * / android / build.gradle手动)。
So there is a way to override jcenter URL with gradle ? 因此,有一种方法可以用gradle 覆盖jcenter URL ?
I have try init script init.gradle in my user home (inspired from doc) : 我在我的用户主目录中尝试过init脚本 init.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
}
}
}
}
}
But when I start gradlew, I get this output : 但是当我开始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
Plugin doesn't seems to intercept jcenter repository... 插件似乎没有拦截jcenter存储库...
In your init script, you are setting contraints on the Project's repositories. 在初始化脚本中,您正在项目的存储库上设置约束。 But as you can see in your error message, Gradle is still trying to download some dependencies from ' https://repo1.maven.org/ ...' and not from your enterprise repo : I guess these are dependencies for the plugins you are applying to your build script.
但是,如您在错误消息中所看到的,Gradle仍在尝试从“ https://repo1.maven.org/ ...”而不是从企业存储库中下载某些依赖项:我想这些是您所用插件的依赖项正在应用于您的构建脚本。 So you have to configure project's buildscript repositories, in addition to project's dependencies repositories.
因此,除了项目的依赖关系存储库之外,还必须配置项目的buildscript存储库。 Following code should work (but I could not test ):
以下代码应该可以工作(但我无法测试):
apply plugin: EnterpriseRepositoryPlugin
class EnterpriseRepositoryPlugin implements Plugin<Gradle> {
private static String ENTERPRISE_REPOSITORY_URL = "https://repo.gradle.org/gradle/repo"
def configRepositories = { ->
// Remove all repositories not pointing to the enterprise repository url
all { ArtifactRepository repo ->
if (!(repo instanceof MavenArtifactRepository) ||
repo.url.toString() != ENTERPRISE_REPOSITORY_URL) {
println "Repository ${repo.name} removed. Only $ENTERPRISE_REPOSITORY_URL is allowed"
remove repo
}
}
// add the enterprise repository
jcenter {
name "BintrayJCenter"
url ENTERPRISE_REPOSITORY_URL
}
}
void apply(Gradle gradle) {
gradle.allprojects { project ->
// ONLY USE ENTERPRISE REPO FOR DEPENDENCIES
project.repositories(configRepositories)
// Only use enterprise repo for plugins classpath as well.
project.buildscript.repositories(configRepositories)
}
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.