Home > Enterprise >  Custom gradle configuration does not let me declare a dependency with exclusions
Custom gradle configuration does not let me declare a dependency with exclusions

Time:11-19

Given this very simple gradle file, declaring a custom configuration myConf and setting a dependency on this configuration:

configurations {
    myConf
}

repositories {
    mavenCentral()
}

dependencies {
    myConf("commons-beanutils:commons-beanutils:1.9.4")
}

When I run gradle dependencies and I get:

> 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

Everything works as expected.

Next I try to define an exclusion on the commons-beanutils dependency (from the docs Excluding transitive dependencies)

configurations {
    myConf
}

repositories {
    mavenCentral()
}

dependencies {
    myConf("commons-beanutils:commons-beanutils:1.9.4") {
        exclude(group = "commons-collections", module = "commons-collections")
    }
}

I now get following error when running 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

CodePudding user response:

It should be exclude(group: "commons-collections", module: "commons-collections")

Looks like you are mixing up the Kotlin syntax with the Groovy one ;)

  • Related