Maven 在多模块项目中复制资源

发布于 2024-12-06 03:52:06 字数 257 浏览 0 评论 0原文

我的需求非常基本,但我找不到任何干净的答案:我只需要能够在多模块项目中分发资源。

让我们以 LICENSE 文件为例,我在此假设所有模块都相同。我不喜欢将其手动复制到每个模块中,因为文件可能会随着时间的推移而改变。我也不想静态链接到项目文件夹外部的资源(即使使用相对路径),因为模块化结构也可能会发生变化。

是否有任何插件可以用来可靠地保证每个模块都获得所需的文件?同样可以接受的是,通过利用父项目的 POM 来获取此类副本,或者由模块化层次结构中的超级项目直接执行。

My need is pretty basic but I could not find any clean answer to it: I simply need to be able to distribute a resource in a multi-module project.

Let us consider for example the LICENSE file, which I hereby assume to be the same for all modules. I prefer not to manually copy it into each and every module because the file could change over time. I also prefer not to statically link to resources (even if using relative paths) outside the project folder, because the modular structure can possibly change too.

Is there any plugin that can be used to robustly guarantee that each module is given the required file? It would be equally acceptable for such copy to be obtained by exploiting the POM of the parent project or directly performed by the super project in the modular hierarchy.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

鲜肉鲜肉永远不皱 2024-12-13 03:52:06

您可以使用程序集和依赖插件..您偶然发现了该链接吗?
http://www.sonatype.com/people/2008/04/how-to-share-resources-across-projects-in-maven/" sonatype.com/people/2008/04/how-to-share-resources-across-projects-in-maven/

它描述了该选项..它从 2008 年开始,但 Maven 是已经有一段时间了..所以我想它或多或少是最新的

编辑关于评论
另一个选项是maven-remote-resources-plugin
有关更详细的示例,请参阅:
http://maven.apache.org/plugins /maven-remote-resources-plugin/examples/sharing-resources.html

由于他们的介绍本身就说明了一切,我引用(maven.apache.org)

此插件用于从远程存储库检索资源 JAR,处理这些资源,并将它们合并到您使用 Maven 构建的 JAR 中。一个非常常见的用例是需要在整个组织中以一致的方式打包某些资源:在 Apache,要求生成的每个 JAR 都包含 Apache 许可证的副本和引用给定项目中所有使用的软件的通知文件.

you could use the assembly and the dependency plugins.. did you stumble over that link?
http://www.sonatype.com/people/2008/04/how-to-share-resources-across-projects-in-maven/

it describes that option ..its from 2008, but maven is around for quite some time.. so I guess its more or less up to date

edit regarding comment
Another option is the maven-remote-resources-plugin.
For a more detailed example see:
http://maven.apache.org/plugins/maven-remote-resources-plugin/examples/sharing-resources.html

Since their intro speaks actually for itself, I quote (maven.apache.org)

This plugin is used to retrieve JARs of resources from remote repositories, process those resources, and incorporate them into JARs you build with Maven. A very common use-case is the need to package certain resources in a consistent way across your organization: at Apache it is required that every JAR produced contains a copy of the Apache license and a notice file that references all used software in a given project.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文