gpt4 book ai didi

gradle - Gradle 是否支持为一个编译时依赖项定义不同的存储库?

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

下面是我的 gradle 文件的片段,我想要实现的是,对于依赖项工件 - com.google.code.gson:2.8.2 单独来说,应该从不同的存储库而不是一个存储库中获取在存储库部分提到?这可能吗?

假设,com.google.code.gson:2.8.2 只能从 https://internal-repo-url/artifactory/second-repo 获取,而不是 https://internal-repo-url/artifactory/第一个仓库。

buildscript {
repositories {
mavenLocal()
maven {
url 'https://internal-repo-url/artifactory/first-repo'
}
}

apply plugin: 'com.choko-build'

dependencies {

compile group: 'org.influxdb', name: 'influxdb-java', version: '2.20'
compile ('org.repo.strung:javacontainer:1.8.16') {
exclude group: 'org.apache.logging.log4j', module: 'log4j-slf4j-impl'
exclude group: 'com.google.code.gson', module: 'gson'
}
compile group: 'org.apache.httpcomponents', name: 'httpclient', version: '4.5.13'
compile group: 'com.google.code.gson', name: 'gson', version: '2.8.2'

最佳答案

是的,这可以通过 Gradle 的存储库过滤机制实现:Declaring content exclusively found in one repository .

例如(未经测试):

repositories {
// This repository will _not_ be searched for artifact "com.google.code.gson:gson:2.8.2"
// despite being declared first
mavenCentral()
exclusiveContent {
forRepository {
maven {
url 'https://internal-repo-url/artifactory/second-repo'
}
}
filter {
// this repository *only* contains artifacts with group "com.google.code.gson:gson:2.8.2"
includeVersion "com.google.code.gson", "gson", "2.8.2"
}
}
}

看看Repository content filtering了解其他可用选项。

关于gradle - Gradle 是否支持为一个编译时依赖项定义不同的存储库?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70951590/

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