简体   繁体   English

在JAR中构建maven多模块项目

[英]Build maven multimodule project in JAR

I have a parent Maven project (pom packaging) and 4 Maven modules (jar packaging) as children of that. 我有一个父Maven项目(pom包装)和4个Maven模块(jar包装)作为其子女。 Is there any way/plugin to create a importable dependency of the parent project including all the children? 是否有任何方法/插件来创建包含所有子项的父项目的可导入依赖项? I mean that I want to create some kind of abstraction, so when somebody wants to import my project, it won't be necessary to import a specific childermodule (the module that he will use), he will just import the whole project (all the children modules) 我的意思是我想创建某种抽象,所以当有人想导入我的项目时,没有必要导入一个特定的childermodule(他将使用的模块),他只会导入整个项目(所有儿童模块)

The Maven parent project corresponds with inheritance . Maven 父项目继承相对应。 It is meant the children projects to inherit the settings, so you do not have to repeat them and you may set all the common stuff in a single place. 这意味着子项目继承设置,因此您不必重复它们,您可以在一个地方设置所有常见的东西。

On other side, the convenience Maven project containing dependencies corresponds with composition . 另一方面, 包含依赖关系的便利Maven项目与组合相对应。

You should not mix these two things together. 你不应该把这两件事混在一起。 Parent project is a common super-class of your modules. 父项目是模块的常见超类 This convenience project you wish to have is a collection containing all your modules as dependencies. 您希望拥有的这个便利项目是一个包含所有模块作为依赖项的集合 You should not want the the Animal class to depend on all the animals. 您不应该希望Animal依赖于所有动物。

Just accept the fact that you need two separate Maven projects: 只需接受您需要两个单独的Maven项目的事实:

  1. the parent (if you need it), and 父母(如果你需要),和
  2. the convenience project for transitive dependencies. 传递依赖的便利项目。

The solution for your problem is described eg here: 3.6.1. 您的问题的解决方案在此处描述: 3.6.1。 Grouping Dependencies 分组依赖关系

If you have a set of dependencies which are logically grouped together. 如果您有一组逻辑上组合在一起的依赖项。 You can create a project with pom packaging that groups dependencies together. 您可以使用pom包创建一个项目,将依赖项组合在一起。 For example, let's assume that your application uses Hibernate... Every project which uses Hibernate might also have a dependency on the Spring Framework and a MySQL JDBC driver. 例如,假设您的应用程序使用Hibernate ...每个使用Hibernate的项目也可能依赖于Spring Framework和MySQL JDBC驱动程序。 Instead of having to include these dependencies in every project that uses Hibernate, Spring, and MySQL you could create a special POM that does nothing more than declare a set of common dependencies. 不必在每个使用Hibernate,Spring和MySQL的项目中包含这些依赖项,您可以创建一个特殊的POM,除了声明一组公共依赖项之外什么都不做。 You could create a project called persistence-deps (short for Persistence Dependencies), and have every project that needs to do persistence depend on this convenience project. 您可以创建一个名为persistence-deps(持久性依赖项的简称)的项目,并让每个需要执行持久性的项目依赖于此便捷项目。

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

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