1
votes

OSGI-INF/serviceComponent.xml can be generated using maven scr felix plugin by adding dependency like

<plugin>
    <groupId>org.apache.felix</groupId>
    <artifactId>maven-scr-plugin</artifactId>
    <version>1.15.0</version>
    <executions>
        <execution>
            <id>generate-scr-scrdescriptor</id>
            <goals>
                <goal>scr</goal>
            </goals>
        </execution>
    </executions>
</plugin>

but for gradle I am not able to generate.. I have tried to add the

buildscript {
dependencies {
    classpath group:'be.jlr-home.gradle' , name:'scrPlugin', version:'0.1.0'

}}
apply plugin: 'java'
`apply plugin: 'eclipse'
 apply plugin: 'maven'
 apply plugin: 'osgi'
   apply plugin: 'scr'

It's giving error that be.jlr-home.gradle not found.

I am doing something wrong???

basically I need the dependency to add in gradle to generate the servicecomponent.xml

3

3 Answers

0
votes

Your maven pom snippet configures the maven plugin for scr from felix. You need a gradle plugin for scr annotation processing. I don't know that felix has one. The bnd project has added gradle support (2.4.0.M1 includes a gradle plugin for bnd) and bnd can process annotations for DS (but maybe not the one's from Felix).

0
votes

I have resolved the issue

add the below lines to your gradle file and it will work.

ant.properties.src = 'src/main/java'

ant.properties.classes = 'build/classes/main' task genscr(dependsOn: compileJava) << { println ant.properties.classes ant.taskdef(resource: 'scrtask.properties', classpath: configurations.compile.asPath) ant.scr(srcdir: ant.properties.src, destdir: ant.properties.classes, classpath: configurations.compile.asPath) }

jar.dependsOn(genscr)
jar {
manifest {


// version = '1.0'
       name = 'xxxxxxxxx'
      instruction 'Service-Component', 'OSGI-INF/<PKGNAME>.<CLASSNAME>.xml'    

}

dependencies {



 ......//All other dependencies........


 compile  'org.apache.felix:org.apache.felix.scr.annotations:1.9.8'
compile 'org.apache.felix:org.apache.felix.scr.ds-annotations:1.2.4'
compile  group: 'org.apache.felix', name: 'org.apache.felix.scr.ant', version: '1.110.'

}

sourceSets.main.compileClasspath += configurations.compile

0
votes

@saviour23's solution did not work for me

It turns out we need to change the buildscript, and that gradle 1.6 does not work; after I upgraded to gradle 2.1, it works fine.

java code:

import org.apache.felix.scr.annotations.*;

@Component
public class Bndtest {
    public static void main(String[] args) {
       System.out.println("Hello World");
    }
}

build.gradle:

buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath 'be.jlr-home.gradle:scrPlugin:0.1.3'
    }
}

apply plugin: 'java'
apply plugin: 'osgi'
apply plugin: 'scr'
apply plugin: 'groovy'
apply plugin: 'maven'


sourceCompatibility = 1.6
targetCompatibility = 1.6

version = '0.0.1-SNAPSHOT'
group = 'be.jlrhome.gradle.scr'
description = 'Gradle scr example'

dependencies {
    compile 'org.apache.felix:org.apache.felix.scr.annotations:1.9.8'
}

gradle will wrap a jar with correct MANIFEST and OSGI XML