1

可以使用 maven scr felix 插件通过添加依赖项来生成 OSGI-INF/serviceComponent.xml

<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>

但对于 gradle 我无法生成.. 我试图添加

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'

它给出了找不到 be.jlr-home.gradle 的错误。

我做错了什么???

基本上我需要在gradle中添加依赖来生成servicecomponent.xml

4

3 回答 3

0

您的 maven pom 片段为 felix 的 scr 配置了 maven 插件。您需要一个用于 scr 注释处理的 gradle 插件。我不知道菲利克斯有一个。bnd 项目添加了 gradle 支持(2.4.0.M1 包括一个用于 bnd 的 gradle 插件)并且 bnd 可以处理 DS 的注释(但可能不是来自 Felix 的注释)。

于 2014-07-29T22:48:22.603 回答
0

@saviour23 的解决方案对我不起作用

事实证明,我们需要更改 buildscript,而 gradle 1.6 不起作用;在我升级到 gradle 2.1 后,它工作正常。

爪哇代码:

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

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

构建.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 将使用正确的 MANIFEST 和 OSGI XML 包装一个 jar

于 2014-10-16T19:07:11.153 回答
0

我已经解决了这个问题

将以下行添加到您的 gradle 文件中,它将起作用。

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

于 2014-07-31T05:47:08.697 回答