使用gradle显示第一个OSGi构建 - 从ant迁移到Gradle

Pau*_*est 26 java osgi manifest.mf gradle

是否首先 显示了OSGi的http://wiki.osgi.org/wiki/Tooling_Approaches gradle插件?或者如何用gradle做到这一点?

OSGi容器有一个很大的旧项目,许多项目在MANIFEST.MF中声明了复杂的关系.构建很长.现在我们想要简化并采用Gradle.但首先不要破坏事物并保持蚂蚁和gradle并行构建一段时间.但是我看到的是gradle建议在里面定义MANIFEST build.gradle. https://docs.gradle.org/current/userguide/osgi_plugin.html
这会使很多复制工作.

更新有近100个模块,模块之间有很多依赖关系信息,嵌套jar.平均MANIFEST.MF长度约为50行(从20到300行不等).如何捆绑嵌套jar是另一个问题.这个问题是关于使用现有的MANIFEST.MF文件.我看到的所有插件bnd都与第一种方法完全相反.

pcz*_*eus 10

Gradle有一个OsgiManifest类,它是一个扩展的jar清单:

https://docs.gradle.org/current/javadoc/org/gradle/api/plugins/osgi/OsgiManifest.html

StackOverflow上有一篇文章显示了类似的用法:

如何为运行时依赖项添加Import-Package指令?

相关的gradle块看起来像这样:

apply plugin: 'java'
apply plugin: 'osgi'

jar {
    baseName = 'awesome'
    manifest {
        name = 'An Awesome Application'
        symbolicName = 'com.example.awesome'
        instruction 'Import-Package', 'org.springframework.orm', '*'
    }
}
Run Code Online (Sandbox Code Playgroud)

如果您有现有清单并希望使用自己的自定义文件,则可以通过在jar闭包中设置清单文件位置来执行此操作:

jar {
    manifest {
        def manif = "${resourcesDir}/MANIFEST.MF"
        if (new File(manif).exists()) {
            from file(manif)
        }
        else{
            name = 'overwrittenSpecialOsgiName'
            instruction 'Private-Package', 'org.mycomp.somepackage'
            instruction 'Bundle-Vendor', 'MyCompany'
            instruction 'Bundle-Description', 'Platform2: Metrics' 
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

可以在此处找到Gradle清单的文档:https: //docs.gradle.org/current/javadoc/org/gradle/api/java/archives/Manifest.html

对于你的"其他问题":

在某些情况下,还有其他用于构建OSGI包的Gradle插件,包括来自其他OSGI包的依赖项.

例如,有一个Gradle Bundle插件,它使用bnd工具,允许您指定包含传递依赖,甚至排除不需要的依赖.举个例子:

jar {
    manifest {
        attributes 'Implementation-Title': 'Bundle Quickstart',     // Will be added to manifest
                     'Import-Package': '*'  // Will be overwritten by the instuctions below
    }
}

bundle {
    includeTransitiveDependencies = true

    instructions << [
        'Bundle-Activator': 'foo.bar.MyBundleActivator',
        'Import-Package': 'foo.*',
        '-sources': true
    ]

    instruction 'Export-Package', '*' // Specify an individual instruction
    instruction '-wab', ''
}
Run Code Online (Sandbox Code Playgroud)

还有Gradle osgi-run插件,默认情况下包含传递依赖项:

dependencies {
    // all your usual dependencies
    ...

    osgiRuntime( "your:dependency:1.0" ) {
        transitive = false // transitive dependencies not included in OSGi runtime
    }
}
Run Code Online (Sandbox Code Playgroud)

希望这足以让你前进.


Pau*_*est 3

截至 2016 年 4 月,OSGi 的 Maven 或 Gradle 构建工具中还没有清单优先的方法。

\n\n

虽然对于 Eclipse 插件(也是有效的 OSGi 捆绑包),有 maven/ tycho构建,这是 Eclipse Foundation 中的标准,但它对于一般 OSGi 项目并没有真正的帮助。

\n\n

与 Manifest-first 相反的是 Manifest 生成,并且只有一个工具bnd,最初用于清单创建,然后发展成为完整的捆绑 jar 构建器,现在具有BndTools Eclipse 集成,看起来类似于管理依赖项的 Maven/Gradle 集成。

\n\n

我建议将bnd指令保留在外部标准bnd.bnd文件中,而不是将其放入构建脚本中。*.bnd文件与通常的 Java 文件类似.properties,因此在 Eclipse IDE 中右键单击,打开方式 -> 其他... 选择选中Properties File Editor“将此编辑器用于..”并选中“将此编辑器用于所有 \'*.nbd\' 文件”

\n\n

对于摇篮

\n\n\n\n

对于行家来说

\n\n\n\n

所有基于 bnd 的工具现在都收集http://bnd.bndtools.org/chapters/700-tools.html上

\n\n

https://github.com/paulvi/OSGiBuildExamples有一些示例

\n\n

注意:当这个问题被打开时,链接http://wiki.osgi.org/wiki/Tooling_Approaches已经处于“OSGi 社区维基不幸被黑客攻击,目前不可用。\n”状态超过一周。

\n\n

可悲的是@Richard 放弃得太早,也没有收到一些感谢(提到maven)

\n