gpt4 book ai didi

android - gradlew 更改 React Native 构建的 jcenter() URL

转载 作者:行者123 更新时间:2023-12-03 03:58:26 24 4
gpt4 key购买 nike

我试图为 android 构建一个 React Native 应用程序,但在我的企业中,外部存储库被阻止(不允许外部网络)。

因此,我们使用内部 Maven 存储库来获取工件。
但是我在构建 React Native 应用程序时遇到了一些问题,因为具有节点模块依赖项的项目需要构建原生 android 代码,引用 jcenter()存储库(我不想手动覆盖 node_modules/react*/android/build.gradle)。

所以有办法覆盖 jcenter URL 用 gradle 吗?

我试过init script我的用户主页中的 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
}
}
}
}
}

但是当我开始 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 存储库...

最佳答案

在您的 init 脚本中,您正在对项目的存储库设置约束。但正如您在错误消息中看到的,Gradle 仍在尝试从“https://repo1.maven.org/”下载一些依赖项。 ...' 而不是来自您的企业存储库:我想这些是您应用到构建脚本的插件的依赖项。
因此,除了项目的依赖存储库之外,您还必须配置项目的 buildscript 存储库。
以下代码应该可以工作(但我无法测试):

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)
}
}

}

关于android - gradlew 更改 React Native 构建的 jcenter() URL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51934907/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com