How to inherit dependency from a parent pom to a child pom

后端 未结 4 544
借酒劲吻你
借酒劲吻你 2020-12-23 17:10

I am new in using maven and jenkins. I am trying to inherit the dependencies from parent pom to child pom it shows the following errors:

[ERROR] COMPILATION          


        
4条回答
  •  执笔经年
    2020-12-23 17:49

    Below is the example of how you should use the parent and child poms.

    The parent pom is as follows:

    .....
    4.0.0
    group1
    group1-artifact
    1.0.1
    pom
    
    
         child1
         // add more childs here
    
    
    
        
            
                org.slf4j
                slf4j-simple
                1.7.21
            
            
                org.abc
                xyz
                1.0.0
            
        
    
    .......
    

    If you specify a dependency in the dependencyManagement tag, it simply means that you are making this jar available for the child pom. It would NOT actually download the jar at this point. The child pom will have to provide the groupId and the artifactId explicitly to download and use the jar to compile its classes. Note: you don't have to include the version of the dependency in the child poms.

    The child pom will be as follows:

    .....
    4.0.0
    
                // this is how you will inherit from parent pom
        group1
        group1-artifact
        1.0.1
    
    
    child1
    
        
            
                org.slf4j
                slf4j-simple
                runtime
                // no version needed as it would inherit from the parent pom
            
            
                org.abc
                xyz
                // no version needed as it would inherit from the parent pom
            
        
    
    .......
    

    It is a good practice to put dependencies common to all the childs in the dependencyManagement tag of the parent pom. This way you can manage the versions of these dependencies from one single place.

提交回复
热议问题