简体   繁体   English

如何将Maven依赖项作为组进行管理?

[英]How to manage maven Dependencies as Group?

I got the following Maven module layout: 我得到以下Maven模块布局:

  • All 所有
    • Sub-Project 1 子项目1
    • Sub-Project 2 子项目2
    • Sub-Project 3 子项目3
    • Sub-Project N 子项目N
    • Deliverable-Build 交付 - 建造
    • Dependency-Report 依赖关系的报告

I manage all my submodule versions in the 'All' as managed dependencies. 我将所有子模块版本在“全部”中作为托管依赖项进行管理。 I reference those managed dependencies in the 'Deliverable-Build' module, to include them in the final zip archive. 我在“ Deliverable-Build”模块中引用了这些托管依赖项,以将它们包括在最终的zip存档中。

The same dependency set needs to be referenced in the 'Dependency Report' module. “依赖关系报告”模块中需要引用相同的依赖关系集。

If the developer creates a new sub-module. 开发人员是否创建新的子模块。 He needs to manually put the new module into 他需要手动将新模块放入

  1. 'All' as managed dependency “全部”作为托管依赖项
  2. 'Deliverable-Build' as dependency “可交付构建”作为依赖项
  3. 'Dependency-Report' as dependency “依赖性报告”作为依赖性

It is easy to forget one of those, so is there a way to simplify this? 很容易忘记其中之一,那么有没有办法简化这一过程呢? eg by once defining a 'dependency group' and reusing it in those three locations? 例如,一次定义一个“依赖组”并在这三个位置重复使用它?

You cannot combine dependencyManagement and dependency lists into one whole. 您不能将dependencyManagement和依赖项列表合并为一个整体。 For no. 没有 2 and 3, you could create a pom containing all relevant dependencies and reference it, as described in 如图2和3所示,您可以创建一个包含所有相关依赖项的pom并引用它,如

How to use POMs as a dependency in Maven? 如何在Maven中将POM用作依赖项?

Let me add two comments: 让我添加两个评论:

  1. Perhaps you can create your Dependency-Report in the Deliverable-Build project, so that you reduce the duplication of logic. 也许您可以在Deliverable-Build项目中创建Dependency-Report,以便减少逻辑重复。 Eg listing all dependencies is done by the Maven-Site-Plugin. 例如,列出所有依赖项是由Maven-Site-Plugin完成的。
  2. I would avoid to create too many modules. 我会避免创建太多模块。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM