【问题标题】:Gradle + OSGi Liferay7 module, include transitive dependenciesGradle + OSGi Liferay7 模块,包含传递依赖
【发布时间】:2017-03-11 06:05:19
【问题描述】:

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

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

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

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

但如果我尝试添加传递性 deps,例如 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]

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

提前感谢您的帮助。

【问题讨论】:

  • 您添加的第二个bnd.bnd sn-p 有错字:我认为应该是lib/module0.jar=module0-1.0.0.jar,而不是lib/module1.jar=module0-1.0.0.jar

标签: java gradle liferay osgi liferay-7


【解决方案1】:

com.liferay.plugin 应用gradle-bundle-plugin 来调用 Bnd 并创建 JAR,因此您可以使用它的所有选项。 This 是您需要的,请将其添加到您的module2build.gradle:

bundle {
    includeTransitiveDependencies = true
}

【讨论】:

  • 就是这样!谢谢。
  • 有谁知道这个的maven等价物吗?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-02-12
  • 2014-12-20
  • 2018-03-13
  • 1970-01-01
  • 1970-01-01
  • 2012-10-09
相关资源
最近更新 更多