Custom Jar Tasks to Create Unique Manifests Result In Duplicate Jars in Ear

I’m new to Gradle and am trying to create a multi-project build where some project artifacts are jar files meant to be stored, along with 3rd party dependencies, inside other projects’ ear/lib directories. Due to project requirements, I need a couple of the projects that produce jar files (‘system’ and ‘shared’ below) to have different manifest information for each ear file they ultimately reside in, but would otherwise be identical. To accomplish this, the ‘system’ and ‘shared’ projects product a default jar, to be used in the ‘earA’ project.

For the ‘earB’ project, I created tasks to manually create the ‘system’ and ‘shared’ jar files, specifying the unique manifest information needed in each for that ear, but this results in duplicate copies of system.jar and shared.jar in the ear/lib directory, one containing the “customized” manifest information and one containing the “default” manifest information.

So I would like to be able to exclude the “default” versions of system.jar and shared.jar from the ear/lib directory, but still keep all of their transitive dependencies (‘group1:name1:1.0’, ‘group2:name2:1.0’, ‘group1:name1:1.0’, and ‘group2:name2:1.0’ in the example build below), along with the ‘customized’ copies of system.jar and shared.jar:

project('system') {
    dependencies {compile 'group1:name1:1.0', 'group2:name2:1.0'}
    jar {manifest {attributes('Implementation-Title': 'system-default')}}
}

project('shared') {
    dependencies {compile project(':system'), 'group1:name1:1.0', 'group2:name2:1.0'}
    jar {manifest {attributes('Implementation-Title': 'shared-default')}}
}

project('shared-web') {
    dependencies {compile project(':system'), project(':shared')}
}

project('earA') {
    dependencies {
      earlib project(':system'), project(':shared'), project(':shared-web')
    }
}

project('earB') {
    task systemCustomJar(type: Jar) {
      from project(':system').sourceSets.main.output
      manifest {attributes('Implementation-Title': 'system-earB')}
    }
    task sharedCustomJar(type: Jar) {
      from project(':shared').sourceSets.main.output
      manifest {attributes('Implementation-Title': 'shared-earB')}
    }
    dependencies {
      earlib files(systemCustomJar), files(sharedCustomJar), project(':shared-web')
    }
}

Again, my ultimate goal is to have system.jar and shared.jar contain different manifest information for every ear they reside in. I would greatly appreciate any help.

Thanks.