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.

http://www.gradle.org/docs/current/dsl/org.gradle.api.artifacts.dsl.DependencyHandler.html

Can you assign a name and group to a selfResolvingDependency?

Related: http://forums.gradle.org/gradle/topics/removing_a_jar_dependency_from_ear

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: http://forums.gradle.org/gradle/topics/removing_a_jar_dependency_from_ear