How do you selectively exclude transitive file dependencies of a jar project?

I’m using a fileTree dependency define to pull in some local filesytem jars for compilation:

dependencies {
    compile fileTree('lib/')

In an Ear project, I define the Jar as a dependency and I need to exclude some of the transitive jars deps. How do you do this?

The fragment below works for maven deps, but how you apply this to jars coming from ‘/lib’?

configurations {
    earlib.exclude group: 'commons-logging'

File dependencies are represented using a SelfResolvingDependency.

Can you assign a name and group to a selfResolvingDependency?


File dependencies have no group, but you should be able to exclude by module name (‘exclude module: …’).

Actually, you may need to use a ‘flatDir’ repository for this to work. See this post: