简体   繁体   中英

How to exclude dependencies from Gradle Version Catalog?

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
            }
        }
    }
}

From a comment on a somewhat unrelated issue:

https://github.com/gradle/gradle/issues/19517#issuecomment-1012159205

(...) the catalog is purely a list of dependencies to pick from.

So, anything else such as exclusions, you must define them as usual in the dependencies { } block.

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")
}
    

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM