Excluding a specific package from a dependency in Gradle

Viewed 68

I have a dependency in one of my project

implementation (group: 'com.ibm.cloud', name: 'ibmcloudsql-jdbc', version: '2.5.34')

I want to specifically exclude a package from this jar, i.e

com.ibm.cloud.sdk.core.http

Is there a way? I already tried this but did not work.

implementation (group: 'com.ibm.cloud', name: 'ibmcloudsql-jdbc', version: '2.5.34'){
    exclude module: 'com.ibm.cloud.sdk.core.http'
  }
1 Answers

You can't use dependency management to remove part of a dependency - with dependency management it's either the complete dependency or no dependency (and this is not limited to gradle - other dependency managers / build systems like maven or ivy also don't have this feature).

The exclude module can only be used to prevent inclusion of transitive dependencies (i.e. you need dependency com.xy:A and com.xy:A declares that it also needs com.xy:B - with exclude module you can prevent the inclusion com.xy:B)

It might be possible to create your own version of that dependency by manually removing the package com.ibm.cloud.sdk.core.http from the jar itself and adding that modified jar file to your project.

Related