Can maven projects have multiple parents?

后端 未结 6 739
我在风中等你
我在风中等你 2020-12-01 04:06

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 c

6条回答
  •  佛祖请我去吃肉
    2020-12-01 04:55

    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.

提交回复
热议问题