EAR Plugin - earlib exclude or provide

Hello,

is it possible to exclude jar-files from an earlib or mark them as provided?

The ear-project looks like this:

apply plugin: 'ear'
  dependencies {
 deploy project(path: ':foo-war', configuration: 'archives')
 deploy project(':foo-service')
 deploy project(':foo-dao')
    earlib project(':foo-entity')
}

The project foo-entity has a dependency to a jar and this is now in the ear lib-folder:

build.gradle of foo-entity
  dependencies {
  compile 'org.glassfish.extras:glassfish-embedded-all:3.1.1'
}

The ear looks like:

lib/foo-entity.jar lib/glassfish-embedded-all.3.1.1.jar foo-war.war foo-service.jar foo-dao.jar

I don’t need the jar in my earlib because it is already part of my glassfish. Is there any way to exclude the jar from the ear lib-folder?

Like:

apply plugin: 'ear'
  dependencies {
 deploy project(path: ':foo-war', configuration: 'archives')
 deploy project(':foo-service')
 deploy project(':foo-dao')
    earlib project(':foo-entity'){
            exclude 'org.glassfish.extras:glassfish-embedded-all:3.1.1'
        }
}

Thanks in advance!

You could use DependencyHandler.add if you want to configure the created ProjectDependency:

dependencies {
    add ('earlib', project(':foo-entity')) {
        exclude group: 'org.glassfish.extras', module: 'glassfish-embedded-all'
    }
}

As simple as that!

Thank you!

A simpler way

dependencies {

earlib (project(’:MyProjectEJBClient’)) {

transitive = false

}

}

How do you exclude a local file dependency from the earlib?

dependencies {
    compile files('lib/custom.jar')
}

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

Related thoughts …

One thing about using the ‘exclude’ method above, is that it will not automatically exclude transitive dependencies of the lib. This means you can still get duplicate jars in the EAR and a global lib/ directory. The war’s plugin ‘provided’ configurations fixes this.

So if you want to create a ‘provided’ configuration for your ear you can do something like this. This code will exclude all of the dependencies in the ‘provided’ configuration from your ‘earlib’.

configurations.create 'provided'
dependencies {
    provided ....
}
configurations.provided.resolvedConfiguration.resolvedArtifacts.each {
    def dep = it.moduleVersion.id
    configurations.earlib {
        it.exclude group:dep.group, module:dep.name
     }
}

Can anyone improve on this?

None of the mentioned solutions works for JBoss libraries. Anyone knows why?