Can maven projects have multiple parents?

后端 未结 6 733
我在风中等你
我在风中等你 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:43

    Even though maven projects have single parent, they can import any number of other pom's like this:

    
        
            
                org.example
                my-shared-dependencies
                0.0.1-SNAPSHOT
                pom
                import
            
        
    
    

    This has two important differences compared to a parent:

    1. Plugins defined in the imported pom won't be imported
    2. Dependencies defined in the imported pom won't be added to the current pom, it will only import dependencies into the dependency management section

    However if your parent pom has a < dependencies> section and you want to include those into your dependencies then you can add the parent to the dependencies section just like a regular dependency :

    
        org.example
        my-shared-dependencies
        0.0.1-SNAPSHOT
    
    

    Even though the same dependency is already imported, the version tag has to be specified again. To reduce duplication, it can be stored in a property

提交回复
热议问题