【问题标题】:Generates the OSGI-INF/serviceComponent.xml using gradle使用 gradle 生成 OSGI-INF/serviceComponent.xml
【发布时间】:2014-07-29 17:10:45
【问题描述】:

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

<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

【问题讨论】:

    标签: java gradle osgi declarative-services


    【解决方案1】:

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

    【讨论】:

    • 嗨,我是 gradle 和声明式服务的新手。你有任何生成 XML 的示例 gradle 文件吗,那太好了..
    【解决方案2】:

    我已经解决了问题

    将以下行添加到您的 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

    【讨论】:

      【解决方案3】:

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

      原来我们需要更改构建脚本,而 gradle 1.6 不起作用;在我升级到 gradle 2.1 后,它工作正常。

      java代码:

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2013-04-10
        • 2014-05-22
        • 2017-12-27
        • 1970-01-01
        • 1970-01-01
        • 2016-07-24
        • 1970-01-01
        • 2017-01-29
        相关资源
        最近更新 更多