Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Excluding dependency from implementation files

I have a jar that I am including in my Android project using the following syntax

implementation files('lib/fm.liveswitch.jar')

fm.liveswitch has a dependency of org.bouncycastle that I am already including as a dependency of my project. How do I exclude bouncycastle from being included as part of the jar?

I have already tried each of the following:

implementation (files('lib/fm.liveswitch.jar')) { 
exclude group: 'org.bouncycastle' 
}

implementation (files('lib/fm.liveswitch.jar')) { 
exclude module: 'org.bouncycastle' 
}

implementation (files('lib/fm.liveswitch.jar'), { 
exclude group: 'org.bouncycastle' 
})

implementation files('lib/fm.liveswitch.jar') { 
exclude group: 'org.bouncycastle' 
}

But each time I get an error similar to the below:

Could not find method exclude() for arguments [{group=org.bouncycastle}] on object of type org.gradle.api.internal.artifacts.dependencies.DefaultSelfResolvingDependency
like image 677
CodeWriter Avatar asked Aug 09 '26 17:08

CodeWriter


1 Answers

When you add file based dependencies, they have no dependency metadata and thus no transitive dependency information.

Given this, there is no point in trying to add an exclude.

Adding implementation files('lib/fm.liveswitch.jar') will only add fm.liveswitch.jar on the classpath, nothing else.

Now if that JAR contains some bouncycastle classes inside, it is a different story. Gradle has no direct way of letting you control the visibility of the contents of a JAR.

You would then have two options:

  • Since it is a local JAR, you can yourself remove the offending classes from it.
  • You could attempt to leverage artifact transforms
like image 181
Louis Jacomet Avatar answered Aug 12 '26 07:08

Louis Jacomet



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!