Gradle 传递存储库和凭据
Gradle transitive repositories and credentials
情况
我有多个 Android 插件使用 JFrog Bintray。这些都位于不同的 maven 存储库中。所有这些都是私有存储库,因此在解决这些依赖关系之前需要进行身份验证。有 project A 和 project B 正在内部开发,还有一个正在开发的 project C由第三方,需要将 Project B 作为依赖项来实现,而后者又依赖于 project A。对于 project A,将有一个 bintray 用户 1 被授予 project A 的权限。还将有一个 bintray 用户 2 供第三方对 project B.
进行身份验证
在 项目 B 中存在对 项目 A 的依赖,如下所示:
repositories {
jcenter()
maven {
credentials {
username = 'bintrayUser1'
password = 'bintrayAPIKeyForUser1'
}
url "https://url-to-projectA"
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.project:A:1.0.0'
}
现在有另一个 项目 C,它依赖于 项目 B,如下所示:
allprojects {
repositories {
jcenter()
maven {
url "https://link-to-projectB"
credentials {
username = 'bintrayUser2'
password = 'bintrayAPIKeyForUser2'
}
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.project:B:1.0.0'
}
问题
出现的问题是bintray用户2被要求告诉项目C其中项目A 是并且需要对其进行身份验证。我想知道 bintray 用户 2 是否有可能不需要告诉 Project C where Project A 找到并从 项目 B 复制它。
身份验证也是如此。 bintray 用户 2 是否可以从 bintray 用户 1 为 Project A 复制身份验证?
非首选解决方案
现在我可以做的是让 项目 C 也告诉 项目 B 中每个依赖项的位置,但这并没有很好地扩展。这将是我将放入 project B、project C 中的每个私有依赖项都需要定位并需要身份验证。它看起来像这样:
allprojects {
repositories {
jcenter()
maven {
url "https://link-to-projectA"
credentials {
username = 'bintrayUser2'
password = 'bintrayAPIKeyForUser2'
}
}
maven {
url "https://link-to-projectB"
credentials {
username = 'bintrayUser2'
password = 'bintrayAPIKeyForUser2'
}
}
maven {
url "https://link-to-projectX"
credentials {
username = 'bintrayUser2'
password = 'bintrayAPIKeyForUser2'
}
}
maven {
url "https://link-to-projectX"
credentials {
username = 'bintrayUser2'
password = 'bintrayAPIKeyForUser2'
}
}
maven {
url "https://link-to-projectX"
credentials {
username = 'bintrayUser2'
password = 'bintrayAPIKeyForUser2'
}
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.project:B:1.0.0'
}
这将变得难以管理,并且您可能不想授予 bintray 用户 2 权限。
那么,有没有办法复制依赖位置和授权?
你必须使用 "nonpreferred solution".
当 Gradle 构建 projectC 时,它从 Maven 中下载依赖项 compile 'com.project:B:1.0.0'
.
对于依赖项,它还会下载包含嵌套依赖项的 pom 文件 com.project:A:1.0.0
。然后它会尝试从您在 projectC/build.gradle
(或顶层)中添加的存储库下载依赖项。
此时gradle不使用projectB/build.gradle,只使用pom文件
这意味着 gradle 无法知道凭据 以下载依赖项而不将它们添加到 projectC/build.gradle
文件中。
情况
我有多个 Android 插件使用 JFrog Bintray。这些都位于不同的 maven 存储库中。所有这些都是私有存储库,因此在解决这些依赖关系之前需要进行身份验证。有 project A 和 project B 正在内部开发,还有一个正在开发的 project C由第三方,需要将 Project B 作为依赖项来实现,而后者又依赖于 project A。对于 project A,将有一个 bintray 用户 1 被授予 project A 的权限。还将有一个 bintray 用户 2 供第三方对 project B.
进行身份验证在 项目 B 中存在对 项目 A 的依赖,如下所示:
repositories {
jcenter()
maven {
credentials {
username = 'bintrayUser1'
password = 'bintrayAPIKeyForUser1'
}
url "https://url-to-projectA"
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.project:A:1.0.0'
}
现在有另一个 项目 C,它依赖于 项目 B,如下所示:
allprojects {
repositories {
jcenter()
maven {
url "https://link-to-projectB"
credentials {
username = 'bintrayUser2'
password = 'bintrayAPIKeyForUser2'
}
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.project:B:1.0.0'
}
问题
出现的问题是bintray用户2被要求告诉项目C其中项目A 是并且需要对其进行身份验证。我想知道 bintray 用户 2 是否有可能不需要告诉 Project C where Project A 找到并从 项目 B 复制它。
身份验证也是如此。 bintray 用户 2 是否可以从 bintray 用户 1 为 Project A 复制身份验证?
非首选解决方案
现在我可以做的是让 项目 C 也告诉 项目 B 中每个依赖项的位置,但这并没有很好地扩展。这将是我将放入 project B、project C 中的每个私有依赖项都需要定位并需要身份验证。它看起来像这样:
allprojects {
repositories {
jcenter()
maven {
url "https://link-to-projectA"
credentials {
username = 'bintrayUser2'
password = 'bintrayAPIKeyForUser2'
}
}
maven {
url "https://link-to-projectB"
credentials {
username = 'bintrayUser2'
password = 'bintrayAPIKeyForUser2'
}
}
maven {
url "https://link-to-projectX"
credentials {
username = 'bintrayUser2'
password = 'bintrayAPIKeyForUser2'
}
}
maven {
url "https://link-to-projectX"
credentials {
username = 'bintrayUser2'
password = 'bintrayAPIKeyForUser2'
}
}
maven {
url "https://link-to-projectX"
credentials {
username = 'bintrayUser2'
password = 'bintrayAPIKeyForUser2'
}
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.project:B:1.0.0'
}
这将变得难以管理,并且您可能不想授予 bintray 用户 2 权限。
那么,有没有办法复制依赖位置和授权?
你必须使用 "nonpreferred solution".
当 Gradle 构建 projectC 时,它从 Maven 中下载依赖项 compile 'com.project:B:1.0.0'
.
对于依赖项,它还会下载包含嵌套依赖项的 pom 文件 com.project:A:1.0.0
。然后它会尝试从您在 projectC/build.gradle
(或顶层)中添加的存储库下载依赖项。
此时gradle不使用projectB/build.gradle,只使用pom文件
这意味着 gradle 无法知道凭据 以下载依赖项而不将它们添加到 projectC/build.gradle
文件中。