Java 从实现文件中排除依赖项

Java 从实现文件中排除依赖项,java,android,gradle,Java,Android,Gradle,我有一个jar,我正在使用以下语法将它包含在我的Android项目中 implementation files('lib/fm.liveswitch.jar') fm.liveswitch有一个org.bounchycastle的依赖项,我已经将它作为我的项目的依赖项包括在内。如何排除bouncycastle作为jar的一部分 我已经尝试了以下各项: implementation (files('lib/fm.liveswitch.jar')) { exclude group: 'org.b

我有一个jar,我正在使用以下语法将它包含在我的Android项目中

implementation files('lib/fm.liveswitch.jar')
fm.liveswitch有一个org.bounchycastle的依赖项,我已经将它作为我的项目的依赖项包括在内。如何排除bouncycastle作为jar的一部分

我已经尝试了以下各项:

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

但每次我都会遇到类似以下的错误:

Could not find method exclude() for arguments [{group=org.bouncycastle}] on object of type org.gradle.api.internal.artifacts.dependencies.DefaultSelfResolvingDependency

添加基于文件的依赖项时,它们没有依赖项元数据,因此没有可传递的依赖项信息

有鉴于此,尝试添加排除是没有意义的

添加
实现文件('lib/fm.liveswitch.jar')
只会在类路径上添加
fm.liveswitch.jar
,而不会添加其他内容

现在,如果这个JAR中包含一些bouncycastle类,那么情况就不同了。Gradle没有直接的方法让您控制罐子内容的可见性

然后,您将有两个选项:

  • 由于它是一个本地JAR,您可以自己从中删除有问题的类
  • 你可以尝试利用