Maven 项目可以有多个父级吗? [英] Can maven projects have multiple parents?

查看:37
本文介绍了Maven 项目可以有多个父级吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们有 Java 和 Flex 项目.我们目前有 1 个基本 pom,其中包含我们要用于两个项目的配置.问题在于:Flex 项目继承配置,例如对于 javadocpmd 插件,这是不可取的.

我想清理它并拥有一个真正的基础 pom,然后是一个 java-base-pom 和一个 flex-base-pom.但是,这在同时具有 Flex 部分和 Java 部分的多模块中如何工作?

我们有自己的应用程序的插件,我们使用以下结构:

  • 我的插件
    • my-plugin-client (flex)
    • my-plugin-server (java)

my-plugin 只包含一个 pom.xml 部分.我会使用 my-plugin pom.xml 作为两者的父级,但是我不能同时使用 java base-pom 或 flex base-pom 作为父级.最好的方法是什么?

解决方案

一个项目只能有一个父级(与 C++ 中的多重继承不同),但该父级可以是更大的父级层次结构的一部分.正如其他人所指出的那样,你可能会有这样的事情:

<前>基础-pom/|-- flex-base-pom||-- 我的插件客户端||`-- pom.xml|`-- pom.xml|-- java-base-pom||-- 我的插件服务器||`-- pom.xml|`-- pom.xml`-- pom.xml

也就是说,我注意到您写道,您的实际问题是:

<块引用>

flex 项目继承了 javadoc 和 pmd 的配置,例如他们不想要的.

您应该使用 pluginManagement 元素来避免这种情况情况:

<块引用>

pluginManagement 是与插件一起出现的元素.插件管理以大致相同的方式包含插件元素,除了不是为此特定项目构建配置插件信息,而是旨在配置从该项目构建继承的项目构建.但是,这仅配置在子项的 plugins 元素中实际引用的插件.孩子们有权覆盖 pluginManagement 定义.

因此,在父 pom 中,在 pluginManagement(例如 javadoc 和 pmd)中配置您的插件,并在所需子项的 plugins 元素中引用它们(仅在我的插件服务器中).这将解决您当前的问题.

We have Java and Flex projects. We currently have 1 base pom that contains the configurations we want to use for both projects. Problem with this is: Flex projects inherit configuration, for example, for javadoc and pmd plugins, which is not desirable.

I want to clean it up and have a real base pom, and then a java-base-pom and a flex-base-pom. But how does this work in a multi-module that has both a Flex part and a Java part?

We have plugins to our own application where we use the following structure:

  • my-plugin
    • my-plugin-client (flex)
    • my-plugin-server (java)

my-plugin just contains a pom.xml with <modules/> section. I would use my-plugin pom.xml as a parent for both, but then I cannot also use the java base-pom or the flex base-pom as parent. What would be the best approach for this?

解决方案

A project can have only one parent (unlike multiple inheritance in C++) but this parent can be part of a bigger parent hierarchy. As pointed out by others, you could thus have something like this:

base-pom/
|-- flex-base-pom
|   |-- my-plugin-client
|   |   `-- pom.xml
|   `-- pom.xml
|-- java-base-pom
|   |-- my-plugin-server
|   |   `-- pom.xml
|   `-- pom.xml
 `-- pom.xml

That said, I noticed you wrote that your actual problem is that:

flex projects inherit configuration for javadoc and pmd for example, which they do not want.

You should use the pluginManagement element to avoid this situation:

pluginManagement is an element that is seen along side plugins. Plugin Management contains plugin elements in much the same way, except that rather than configuring plugin information for this particular project build, it is intended to configure project builds that inherit from this one. However, this only configures plugins that are actually referenced within the plugins element in the children. The children have every right to override pluginManagement definitions.

So, in the parent pom, configure your plugins in pluginManagement (javadoc and pmd for example), and reference them within the plugins element in the desired children (only in my-plugin-server here). This would solve your current issue.

这篇关于Maven 项目可以有多个父级吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆