Gradle + OSGi Liferay7 模块,包括传递依赖

Gradle + OSGi Liferay7 module, include transitive dependencies

我构建了一个具有以下结构和依赖项的示例模块:

osgi-lfr-module
+--- module0
|     \--- org.apache.commons:commons-lang3:3.5
+--- module1
|     \--- module0
\--- module2
      +--- module1
      \--- org.apache.commons:commons-collections4:4.1

我想构建一个 jar 以部署在包含模块 0、1 和 2 以及第 3 方依赖项的 Liferay 7 中。我知道这不是推荐的方法,但我想知道如何实现它。

module2/build.gradle 文件是:

buildscript {
    dependencies {
        classpath 'com.liferay:com.liferay.gradle.plugins:2.0.10'
    }   
}

apply plugin: "com.liferay.plugin"

sourceCompatibility = "1.8"
targetCompatibility = "1.8"

dependencies {
    compile project(':module1')

    compile group: 'org.apache.commons', name: 'commons-collections4', version: '4.1'
}

我已按照 OSGi Module Dependencies 中的步骤操作。到目前为止,我可以在 module2/bnd.bnd:

中添加直接依赖项
Bundle-Version: 1.0.0
Export-Package: com.test.module2, com.test.module1, com.test.module0
Bundle-ClassPath: \
    .,\
    lib/module1.jar,\
    lib/commons-collections4.jar
-includeresource: \
    lib/module1.jar=module1-1.0.0.jar,\
    lib/commons-collections4.jar=commons-collections4-4.1.jar

但是如果我尝试添加传递依赖,比如 module0:

Bundle-ClassPath: \
    .,\
    lib/module0.jar,\
    lib/module1.jar,\
    lib/commons-collections4.jar
-includeresource: \
    lib/module0.jar=module0-1.0.0.jar,\
    lib/module1.jar=module1-1.0.0.jar,\
    lib/commons-collections4.jar=commons-collections4-4.1.jar

构建失败并出现以下错误:

:module2:jar
[Input file does not exist: module0-1.0.0.jar]
[No sub JAR or directory lib/module0.jar]

谁能帮我找出我做错了什么?还有,有什么方法可以减少手动添加传递依赖项吗?

在此先感谢您的帮助。

com.liferay.plugin适用 gradle-bundle-plugin to invoke Bnd and create the JAR, so you can use all its options. This是您需要的,请添加到您的模块2build.gradle:

bundle {
    includeTransitiveDependencies = true
}