What is the difference between “pom” type dependency with scope “import” and without “import”?

后端 未结 3 1324
-上瘾入骨i
-上瘾入骨i 2020-11-30 18:07

Starting from Maven 2.0.9 there is possibility to include

pom
import

in the <

3条回答
  •  我在风中等你
    2020-11-30 18:20

    You can only import managed dependencies. This means you can only import other POMs into the dependencyManagement section of your project's POM. i.e.

    ...
    
        
            
                other.pom.group.id
                other-pom-artifact-id
                SNAPSHOT
                import
                pom
               
        
    
    ...
    

    What then happens is that all the dependencies defined in the dependencyManagement section of the other-pom-artifact-id are included in your POM's dependencyManagement section. You can then reference these dependencies in the dependency section of your POM (and all of its child POMs) without having to include a version etc.

    However if in your POM you simply define a normal dependency to other-pom-artifact-id then all dependencies from the dependency section of the other-pom-artifact-id are included transitively in your project - however the dependencies defined in the dependencyManagement section of the other-pom-artifact-id are not included at all.

    So basically the two different mechanisms are used for importing/including the two different types of dependencies (managed dependencies and normal dependencies).

    There is a good page on the maven website, which can explain this far better than I can, Dependency Management in Maven and it also contains specific information on importing dependencies.

提交回复
热议问题