3 回答

TA贡献1890条经验 获得超9个赞
您可以在应用插件后删除依赖项,(从单个配置或所有配置)使用例如。compile.exclude. 请注意,compile解析为“配置”;请参阅Configuration.exclude中的 javadoc 。
编辑
请注意,如果配置已经解析,则排除依赖项可能会失败。
示例脚本
apply plugin: 'java-library'
repositories {
jcenter()
}
dependencies {
compile 'junit:junit:4.12'
compile 'ant:ant:1.6'
compile 'org.apache.commons:commons-lang3:3.8'
}
// remove dependencies
configurations.all {
exclude group:'junit', module:'junit'
}
configurations.compile {
exclude group:'org.apache.commons', module: 'commons-lang3'
}
println 'compile deps:\n' + configurations.compile.asPath

TA贡献1851条经验 获得超5个赞
您可以通过以下方式操作构建脚本本身的类路径:
buildscript {
configurations {
classpath {
exclude group: 'org', module: 'foo' // For a global exclude
}
}
dependencies {
classpath('org:bar:1.0') {
exclude group: 'org', module: 'baz' // For excluding baz from bar but not if brought elsewhere
}
}
}

TA贡献1811条经验 获得超5个赞
这是强制您的项目严格使用特定版本的 build.gradle.kts 的另一种方法
val grpcVersion = "1.45.1"
implementation("io.grpc:grpc-stub") {
version {
strictly(grpcVersion)
}
}
更多信息可以在 gradle 文档中找到:https ://docs.gradle.org/current/userguide/dependency_downgrade_and_exclude.html
添加回答
举报