给定这个非常简单的gradle文件,声明一个自定义配置myConf
并设置对该配置的依赖关系:
configurations {
myConf
}
repositories {
mavenCentral()
}
dependencies {
myConf("commons-beanutils:commons-beanutils:1.9.4")
}
当我运行gradle dependencies
时,得到:
> Task :dependencies
------------------------------------------------------------
Root project 'tmp-project'
------------------------------------------------------------
myConf
\--- commons-beanutils:commons-beanutils:1.9.4
+--- commons-logging:commons-logging:1.2
\--- commons-collections:commons-collections:3.2.2
A web-based, searchable dependency report is available by adding the --scan option.
BUILD SUCCESSFUL in 1s
1 actionable task: 1 executed
一切都按预期运行。
接下来,我尝试定义commons-beanutils
依赖项的排除(来自文档Excluding transitive dependencies)
configurations {
myConf
}
repositories {
mavenCentral()
}
dependencies {
myConf("commons-beanutils:commons-beanutils:1.9.4") {
exclude(group = "commons-collections", module = "commons-collections")
}
}
现在运行gradle dependencies
时出现以下错误
FAILURE: Build failed with an exception.
* Where:
Build file '/__path-to-tmp-project__/build.gradle' line: 11
* What went wrong:
A problem occurred evaluating root project 'tmp-project'.
> Cannot set the value of read-only property 'group' for DefaultExternalModuleDependency{group='commons-beanutils', name='commons-beanutils', version='1.9.4', configuration='default'} of type org.gradle.api.internal.artifacts.dependencies.DefaultExternalModuleDependency.
* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.
* Get more help at https://help.gradle.org
1条答案
按热度按时间s3fp2yjn1#
应该是
exclude(group: "commons-collections", module: "commons-collections")
看起来您混淆了Kotlin语法和Groovy语法;)