Hi,

I'm also working on a gradle build including OSGi manifest generation and
ran into the same problem. In my work in progress I have the following
pattern for some maven style test jars that are OSGi-fied for use inside
SpringSource Tool Suite. (Not entirely happy with that construct, but I'd
like the gradle build to be compatible with our maven build for starters)

Anyway to the code (any comments/criticism welcome):

In the main build.gradle:

subprojects {
        apply plugin: 'java'
        apply plugin: 'osgi'

  ......

        afterEvaluate { Project project ->
                if( project.hasProperty('hasTestJar') && project.hasTestJar
) {
                        task testJar(type: Jar, dependsOn: [compileTestJava,
processTestResources]) {
                                description = "Create a test jar that can be
used as OSGi bundle"
                                from sourceSets.test.classesDir
                                includes = ['**/*.class', '**/*.html']
                                classifier = 'tests'

                                manifest = osgiManifest {
                                        symbolicName = project.name+".test"
                                        name = project.name+".test"
                                        description = "Test Bundle for "+
project.name
                                        if( project.hasProperty('version')
) {
                                                version = project.version
                                        } else {
                                                version = '1.0.0'
                                        }

                                        vendor = 'Educator'
                                        docUrl = 'http://www.educator.eu'

                                        instruction 'nouses', 'false'
                                        instruction 'plugin',
'aQute.lib.spring.SpringComponent'
                                        if(
project.hasProperty('testOsgiExport') ) {
                                                project.testOsgiExport.each
{ String export -> instruction 'Export-Package', export }
                                        }

                                        classesDir =
sourceSets.test.classesDir
                                        classpath =
sourceSets.test.runtimeClasspath

                                        metaInf {
                                                // exclude bundlor
manifest.mf
                                                exclude('MANIFEST.MF')
                                        }
                                }
                        }

Then in subprojects:

hasTestJar = true
testOsgiExport = ['eu.educator.catalog.test.*']

This is still pretty rough, my groovy skills are not very good so it can
probably look nicer :)

My guess is that the same pattern could be applied to the normal bundles. My
first try at it lead to a lot of copy paste, I never finished that part
though since we usually generate manifests by hand inside STS.

Hope this gives some ideas.

Cheers,

Ric

Reply via email to