Multiple JAR files using the Osgi plugin

My use case is that I want to 3 Jar files for my build, 2 with different OSGi manifests and one for the tests. I have made it work, but I’m not happy with the cleanliness of the solution (and I’m new to Gradle). I would like some advice as to how keep DRY. I think the root of the problem I’m having is the osgi task injects itself as the manifest handler into the “jar” task, but if I create my own Jar tasks, it will not do that, so I have to do it myself.

I would be grateful for any suggestions for improvement.

Here is my code:

jar {
    manifest {
        name = 'Library Jar'
        //instruction 'xxx'
    }
}

OsgiPluginConvention conv = getConvention().getPlugins().get('osgi')

task bundleJar(type: Jar) {
    from sourceSets.main.output
    classifier 'bundle'
    setManifest conv.osgiManifest {
        setClassesDir sourceSets.main.output.classesDir
        setClasspath configurations.getByName("runtime");
        name = 'Bundle Jar'
        //instruction 'xxx'
    }
}

task testJar(type: Jar) {
    from sourceSets.test.output
    classifier 'tests'
    setManifest conv.osgiManifest {
        setClassesDir sourceSets.main.output.classesDir
        setClasspath configurations.getByName("runtime");
        name = 'Test Jar'
        //instruction 'xxx'
    }
}

jar.dependsOn bundleJar, testJar