自定义gradle配置不允许我声明包含排除项的依赖项

bz4sfanl  于 2022-11-24  发布在  其他
关注(0)|答案(1)|浏览(146)

给定这个非常简单的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
s3fp2yjn

s3fp2yjn1#

应该是exclude(group: "commons-collections", module: "commons-collections")
看起来您混淆了Kotlin语法和Groovy语法;)

相关问题