1

我需要用 common ( ) 存档的结构打包一个jar(或war格式无关,请进一步阅读)。这意味着我需要充满 dep-cy的文件夹(不是扁平/阴影)和所有常见的东西,如资源等。warwabWEB-INF/classes/libjar

因此,与非常常见的 NON-osgi 的主要区别war在于正确编写的清单。问题是,任务的BND进程,然后战争插件搞砸了一切。JarGradle

现在我已经找到了解决方案,但我对此并不满意。总的来说,我觉得应该有更好的方法。主要有两种策略:

  1. 不使用war插件并依赖BND丰富的功能。
  2. 使用war插件,但以某种方式重新排列构建,所以它做它的事情,但让它做它的BND事情,据说在war. (所以,首先是WARBND之后。)

一点输入数据。我相信这是 bnd 中的一个主要 SUPER_BUG,因为我所说的所有内容都应该只使用一个指令-wablib,但是,它的主要问题是它以不同的方式而不是例如以某种方式-includeresource工作。-wablib获取某种 full_path_to_resource 的输入,这在 gradle 和总体上进行项目评估和解决时不可用,如果它可以采取同样的jar_name.jar方式,它可能会很棒includeresource。但事实并非如此!因此,即使在尝试提取具有所有依赖项的完整路径的字符串之后,也永远不会gradle's configuration is not allowed to be manually resolved获取这些路径。

另一方面,第二种列出的方式有效,但它看起来和感觉就像一根拐杖。好像不应该那样。我的意思是手动构建Bundle-ClassPathandInclude-Resources

如何使用插件轻松创建WARs而不是扁平/阴影?WABwar gradle

片段(更新

我设法通过添加;lib:=truebnd 来避免显式构造 manifestClasspath 。

tasks.withType<Jar> {
    manifest {
        val manifestIncludeJars = configurations.
                implementation.
                incoming.
                dependencies.
                joinToString(",") {
                    "lib/${it.name}.jar=${it.name}-[0-9]*.jar;lib:=true"
                }
        attributes(mapOf(
                SNAPSHOT                to "\${tstamp}-SNAPSHOT",
                "Automatic-Module-Name" to "${project.group}.\${replace;\${bsn};[-_];.}",
                BUNDLE_VERSION          to project.version,
                INCLUDERESOURCE         to manifestIncludeJars
        ))
    }
}

更新

我也设法通过使用没有 gradle 'war' 插件的 bnd 来获得我想要的东西。但这不是我想要的。这构造了整个jar//无论你叫什么warwab它的结构与 gradle 'war' 插件和正确的清单完全相同,但我想将正确的清单创建与组装档案分开,所以没有从 gradle 到 bnd 的委托工具功能

# [ WEB(APP) / WAB / WAR ]
-wab: src/main/webapp
-includeresource: WEB-INF/classes=src/main/resources
# This does the magic since gradle and bnd share properties during build
deps: ${project.sourceSets.main.runtimeClasspath.files}
# remove the square bracket form the last dependency so it to be incuded in archive
lastDep: {substring;${last;${deps}};0;-1}
-wablib: ${format;%s,;${filter;${deps},${lastDep};.*\.jar$}}
4

1 回答 1

0

最后,BJ Hargrave 表示,没有直接的方法可以同时使用 WAR Gradle 插件和 bnd Gradle 插件,所以只能选择其中一种。Bnd Gradle 插件不支持与带有 Gradle WAR 插件的规范战争项目相同的目录结构,因此可能会有困难。此外,生成的工件尽管具有类似 WAR 的结构,但它仍然是.jar. 但一般来说,我只需使用 bnd-tools Gradle 插件就可以实现所需的结构。

PS问题和答案仅适用于非工作区设置和bnd-gradle-builder插件

这是我的战争(例如网络)项目bnd.bnd(非工作区)

#     ___   ___     ____  ____________  ________ __________
#    / _ | / _ \__ / / / / / __/_  __/ /_  __/ // /  _/ __/
#   / __ |/ // / // / /_/ /\ \  / /     / / / _  // /_\ \
#  /_/ |_/____/\___/\____/___/ /_/     /_/ /_//_/___/___/
#
# ADJUST THIS

# [ BLUEPRINT ] //overrides Blueprint header if exists
Bundle-Blueprint:

# [ IMPEXP ]
-exportcontents: ${packages;ANNOTATED;org.osgi.annotation.versioning.Version}
Import-Package: *

# [ WEB(APP) / WAB / WAR ]
Web-ContextPath: /myapp
# //Pax Web support not 100% OSGi 4.2 compliant https://ops4j1.jira.com/browse/PAXWEB-206
Webapp-Context: /myapp
-wab: src/main/webapp
# // for instance regex for end and start (^\[)|(\]$)
-wablib: ${format;%s,;${filter;${substring;${project.sourceSets.main.runtimeClasspath.files};1;-1};.*\.jar$}}

#     __   ______ __________  __  _  ______    _______ _____   _  _______________
#    / /  /  _/ //_/ __/ /\ \/ / / |/ / __ \  / ___/ // / _ | / |/ / ___/ __/ __/
#   / /___/ // ,< / _// /__\  / /    / /_/ / / /__/ _  / __ |/    / (_ / _/_\ \
#  /____/___/_/|_/___/____//_/ /_/|_/\____/  \___/_//_/_/ |_/_/|_/\___/___/___/
#
# // probably no changes needed

Bundle-Description: ${project.description}
Bundle-DocURL: ${project.bundleDocURL}
Bundle-Version: ${project.version}
Automatic-Module-Name: ${project.group}.${replace;${bsn};[-_];.}

-snapshot: ${tstamp}-SNAPSHOT
-pedantic: true
-sources: false
-runee: JavaSE-${project.javaManifestVersion}
-pom: true
-fixupmessages: "Classes found in the wrong directory";is:=warning

非战争(非网络)项目

#     ___   ___     ____  ____________  ________ __________
#    / _ | / _ \__ / / / / / __/_  __/ /_  __/ // /  _/ __/
#   / __ |/ // / // / /_/ /\ \  / /     / / / _  // /_\ \
#  /_/ |_/____/\___/\____/___/ /_/     /_/ /_//_/___/___/
#

# [ BLUEPRINT ] //overrides Blueprint header if exists
Bundle-Blueprint:

# [ IMPEXP ]
-exportcontents: ${packages;ANNOTATED;org.osgi.annotation.versioning.Version}
Import-Package: *

#     __   ______ __________  __  _  ______    _______ _____   _  _______________
#    / /  /  _/ //_/ __/ /\ \/ / / |/ / __ \  / ___/ // / _ | / |/ / ___/ __/ __/
#   / /___/ // ,< / _// /__\  / /    / /_/ / / /__/ _  / __ |/    / (_ / _/_\ \
#  /____/___/_/|_/___/____//_/ /_/|_/\____/  \___/_//_/_/ |_/_/|_/\___/___/___/
#

# // probably no changes needed
Bundle-Description: ${project.description}
Bundle-DocURL: ${project.bundleDocURL}
Bundle-Version: ${project.version}
Automatic-Module-Name: ${project.group}.${replace;${bsn};[-_];.}

-snapshot: ${tstamp}-SNAPSHOT
-pedantic: true
-sources: false
-runee: JavaSE-${project.javaManifestVersion}
-pom: true
-fixupmessages: "Classes found in the wrong directory";is:=warning

另外,从那时起 bnd-tools 开始支持多 jar 项目,所以fixupmessages可以避免,也许应该相应地调整一些其他的东西。

于 2018-12-22T12:02:26.210 回答