gpt4 book ai didi

java - 在 JAR 中构建 Maven 多模块项目

转载 作者:太空宇宙 更新时间:2023-11-04 11:37:36 25 4
gpt4 key购买 nike

我有一个父 Maven 项目(pom 打包)和 4 个 Maven 模块(jar 打包)作为其子项目。有没有什么方法/插件可以创建父项目(包括所有子项目)的可导入依赖项?我的意思是我想创建某种抽象,所以当有人想要导入我的项目时,不需要导入特定的子模块(他将使用的模块),他只需导入整个项目(所有子模块)

最佳答案

Maven 父项目对应于继承。这意味着子项目继承设置,因此您不必重复它们,并且可以在一个地方设置所有常见的内容。

另一方面,方便的 Maven 项目包含依赖项组合相对应。

你不应该把这两种东西混在一起。父项目是模块的常见父类(super class)。您希望拥有的这个便利项目是一个包含所有模块作为依赖项的集合。您不应该希望 Animal依赖所有动物。

接受您需要两个单独的 Maven 项目的事实:

  1. 父级(如果需要的话),以及
  2. 传递依赖项的便捷项目。

描述了您的问题的解决方案,例如这里: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. 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. 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. 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.

关于java - 在 JAR 中构建 Maven 多模块项目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43104534/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com