Maven dependency within dependency with different scope

后端 未结 4 1744
深忆病人
深忆病人 2020-12-16 15:19

Say I have two Maven dependencies defined in a project like below.

    
        com.thoughtworks.xstream
            


        
4条回答
  •  执笔经年
    2020-12-16 15:42

    This feels really odd to me, and if it's "feature", I think it is a really dangerous one. Anyway, it's not a Maven bug and it's in the maven documentation here.

    Regarding best practices on this issue, I haven't heard of any, but the safest way to proceed ought to be to entirely remove xstream from your pom, relying on the transitive dependency. Doing this will result in a build failure if the dependency to mylibrary is removed. This will act as a notification to you that you need to fix something. You won't silently loose required dependencies, and you won't silently have dependencies you no longer need.

    On a side note, mvn dependency:analyze can be used to check for dependencies that are included but not used.

提交回复
热议问题