Maven - Dependency Inheritance - Provided

后端 未结 1 1593
伪装坚强ぢ
伪装坚强ぢ 2021-02-14 03:52

I make use of dependency POMs which I will then go and include into another projects as as dependency. The problem I am having is while it aggregates the POM with those depende

1条回答
  •  后悔当初
    2021-02-14 04:06

    If a dependency is provided why can't that dependency be inherited with the same scope so I don't have to declare it?

    It is inherited with the same scope. Given the following parent pom.xml:

    
      4.0.0
      com.stackoverflow.Q3597684
      root
      1.0-SNAPSHOT
      Q3597684 - Root
      pom
      
        
          javax.servlet
          servlet-api
          2.5
          provided
        
        
          junit
          junit
          3.8.1
          test
        
      
    
    

    And the following pom.xml that inherits from the root artifact:

    
      4.0.0
      
        root
        com.stackoverflow.Q3597684
        1.0-SNAPSHOT
      
      child
      war
      Q3597684 - Child
      
    
    

    Running mvn dependency:tree from the child gives the following output:

    $ mvn dependency:tree[INFO] Scanning for projects...
    [INFO] Searching repository for plugin with prefix: 'dependency'.
    [INFO] ------------------------------------------------------------------------
    [INFO] Building Q3597684 - Child
    [INFO]    task-segment: [dependency:tree]
    [INFO] ------------------------------------------------------------------------
    [INFO] [dependency:tree {execution: default-cli}]
    [INFO] com.stackoverflow.Q3597684:child:war:1.0-SNAPSHOT
    [INFO] +- javax.servlet:servlet-api:jar:2.5:provided
    [INFO] \- junit:junit:jar:3.8.1:test
    [INFO] ------------------------------------------------------------------------
    [INFO] BUILD SUCCESSFUL
    [INFO] ------------------------------------------------------------------------
    

    The provided servlet-api is there, as expected.

    Are you maybe (mis)using the dependencyManagement section?

    0 讨论(0)
提交回复
热议问题