Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In the maven dependency tree does the parent dependency override the scope of the child?

Tags:

java

maven

If i have the following output from running mvn dependency:tree are the jars that are brought in test or compile scope?

[INFO] |  +- io.springfox:springfox-swagger1:jar:2.5.0:test
[INFO] |  |  +- io.springfox:springfox-schema:jar:2.5.0:compile
[INFO] |  |  +- io.springfox:springfox-swagger-common:jar:2.5.0:compile
like image 972
Metin Dagcilar Avatar asked Jan 26 '26 15:01

Metin Dagcilar


2 Answers

It will be test. But this is not a general rule for all scope pairs. In your case, this holds:

For the test scope, both runtime and compile scope transitive dependencies will be pulled in with the test scope, in the project.

More details can be found at https://www.baeldung.com/maven-dependency-scopes

In your example all three dependencies are effectively test scoped. As per Dependency Scope docs any transitive compile scoped dependency of a test scoped dependency becomes test scope:

Each of the scopes (except for import) affects transitive dependencies in different ways, as is demonstrated in the table below. If a dependency is set to the scope in the left column, transitive dependencies of that dependency with the scope across the top row will result in a dependency in the main project with the scope listed at the intersection. If no scope is listed, it means the dependency will be omitted.

            compile     provided        runtime     test
compile     compile     -               runtime     -
provided    provided    -               provided    -
runtime     runtime     -               runtime     -
test        test        -               test        -
like image 27
Karol Dowbecki Avatar answered Jan 28 '26 05:01

Karol Dowbecki



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!