Maven dependency within dependency with different scope

后端 未结 4 1752
深忆病人
深忆病人 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:34

    By declaring your own dependency on xstream, and setting the scope to test, you are overriding the dependencies declared by mylibrary.

    This is actually a Maven feature - it allows you to do things such as depend on a later version of a transitive dependency within your own project, and not end up packaging two different versions of the same artifact. For example, you might depend on version 1.2.15 of log4j, but because you also use libraryX which depends on log4j-1.2.14 - you wouldn't want both log4j-1.2.15 and log4j-1.2.14 to be packaged with your project.

    If you actually want xstream to be packaged within your project, you should not be declaring the scope as test. In fact if you remove your listed dependency on xstream, things will work out as you like, since mylibrary has a compile dependency on it..

提交回复
热议问题