How to exclude dependencies from Gradle Version Catalog?

Viewed 392

I'd like to perform the equivalent to the following declaration:

dependencies {
    implementation('commons-beanutils:commons-beanutils:1.9.4') {
        exclude group: 'commons-collections', module: 'commons-collections'
    }
}

But within the version catalog feature. Something like:

dependencyResolutionManagement {
    versionCatalogs {
        libs {
            library('commons-lang3', 'org.apache.commons', 'commons-lang3').exclude {
                // group, module etc
            }
        }
    }
}
3 Answers

There's a simple way to do this, which unfortunately isn't documented:

implementation dependencies.create(libs.commons.beanutils.get()) {
    exclude group: 'commons-collections', module: 'commons-collections'
}

Note the get() call - beanutils in this case is an instance of Provider<?> so you need to manually unwrap it.

this is pretty ugly but works

in kotlin for example:

vorbisspi = "com.googlecode.soundlibs:vorbisspi:1.0.3.3"
implementation(libs.mp3spi.get().let { "${it.module}:${it.versionConstraint.requiredVersion}" }) {
    exclude("javazoom.spi", "spi")
    exclude("junit", "junit")
}
    
Related