【问题标题】:How to package jar from one project to another in maven multimodule project如何在maven多模块项目中将jar从一个项目打包到另一个项目
【发布时间】:2017-03-28 08:26:18
【问题描述】:

我需要针对以下问题的最佳实践解决方案。我有一个包含 3 个子项目的 Maven 多模块项目:

  • 客户端模块(简单的java应用,打包为.jar)
  • module-1-that-uses-client
  • module-2-that-uses-client

module-*-that-uses-client 是一堆静态 xml 配置文件,其中包含一个打包为 .zip 文件的 client-module.jar。因此,module-*-that-uses-client 的打包结构如下所示:

  • client-module.jar
  • config1.xml
  • config2.xml
  • config3.xml

我想知道如何实施以下构建策略。 如果我构建客户端模块,那么:

  1. 构建客户端模块
  2. 将 client-module.jar 复制到所有 module-*-that-uses-client
  3. 构建所有 module-*-that-uses-client 模块。

如果我构建任何 module-*-that-uses-client,那么:

  1. 构建客户端模块
  2. 将 client-module.jar 复制到确切的 module-*-that-uses-client
  3. 构建精确的模块-*-使用客户端模块。

感谢您对此问题的任何帮助。

【问题讨论】:

    标签: maven dependencies maven-plugin packaging multi-module


    【解决方案1】:

    一种解决方案是使用--also-make--also-make-dependents

    --also-make 构建指定模块的所有依赖项。示例:mvn --projects module-1-that-uses-client --also-make clean install 按此顺序构建 client-module 和 module-1-that-uses-client。

    --also-make-dependents 构建指定的模块和所有其他依赖于指定模块的模块。示例:mvn --projects client-module --also-make-dependents clean install 构建第一个客户端模块,然后构建两个模块-*-that-uses-client。

    另请参阅Guide to Working with Multiple Modules

    【讨论】:

    • 罗兰,感谢您的回答。可以使用 maven-assembly 从 maven 仓库中放依赖吗?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-12-29
    • 1970-01-01
    • 2019-06-19
    • 2020-10-10
    • 2018-03-24
    • 2012-09-08
    • 2011-11-05
    相关资源
    最近更新 更多