Exclude Gradle transitive dependencies

7.1k Views Asked by At

I am trying to exclude a nested transitive dependency from the gradle build. The dependency structure looks like

+---org.apache.beam:beam-sdks-java-core:2.33.0-custom

+---META-INF/maven/org.apache.commons/commons-compress/

enter image description here

I excluded the dependency by following the accepted solution from gradle exclude a transitive dependency but it didnt work for me.

implementation('core-lib:tag') {
    implementation('org.apache.beam:beam-sdks-java-core:2.33.0-custom') {
        exclude group: 'org.apache.commons'
    }
}

This doesnt exclude the dependency. When I change this to * the dependencies are still not excluded.

implementation('core-lib:tag') {
    implementation('org.apache.beam:beam-sdks-java-core:2.33.0-custom') {
        exclude group: '*', module:'*'
    }
}

Any suggestions on how can i exclude this dependency? Its pulling in an older version.

2

There are 2 best solutions below

1
PrasadU On

it should be as below - optionally you can add module see https://docs.gradle.org/current/userguide/dependency_downgrade_and_exclude.html#sec:excluding-transitive-deps

implementation('core-lib:tag') {
    exclude group: 'org.apache.commons'
}
0
monkunashi On

If you want to remove the one in the image, all you need to do is specify that one specifically. If you leave it off, it will exclude the entire group; so you add the specific name so it only excludes that one.

implementation('core-lib:tag') {
    exclude group: 'org.apache.commons', module: 'commons-compress'
}