How can I exclude a dependency transitively?

2.2k views Asked by At

I have all following dependency:tree.

...
[INFO] +- org.springframework.boot:spring-boot-starter-test:jar:2.1.5.RELEASE:test
[INFO] |  +- org.springframework.boot:spring-boot-test:jar:2.1.5.RELEASE:test
[INFO] |  +- org.springframework.boot:spring-boot-test-autoconfigure:jar:2.1.5.RELEASE:test
[INFO] |  +- com.jayway.jsonpath:json-path:jar:2.4.0:test
[INFO] |  |  \- net.minidev:json-smart:jar:2.3:test
[INFO] |  |     \- net.minidev:accessors-smart:jar:1.2:test
[INFO] |  |        \- org.ow2.asm:asm:jar:5.0.4:test
[INFO] |  +- junit:junit:jar:4.12:test
...

And I did do this.

<dependency>
  <groupId>org.springframework.boot</groupId>
  <artifactId>spring-boot-starter-test</artifactId>
  <exclusions>
    <exclusion>
      <groupId>junig</groupId>
      <artifactId>junit</artifactId>
    </exclusion>
  </exclusions>
  <scope>test</scope>
</dependency>

Now I see this.

..
[INFO] +- org.springframework.boot:spring-boot-starter-test:jar:2.1.5.RELEASE:test
[INFO] |  +- org.springframework.boot:spring-boot-test:jar:2.1.5.RELEASE:test
[INFO] |  +- org.springframework.boot:spring-boot-test-autoconfigure:jar:2.1.5.RELEASE:test
[INFO] |  +- com.jayway.jsonpath:json-path:jar:2.4.0:test
[INFO] |  |  \- net.minidev:json-smart:jar:2.3:test
[INFO] |  |     \- net.minidev:accessors-smart:jar:1.2:test
[INFO] |  |        \- org.ow2.asm:asm:jar:5.0.4:test
[INFO] |  +- junit:junit:jar:4.12:test

Is there any way to exclude a specific artifact transitively?

2

There are 2 answers

1
J Fabian Meier On BEST ANSWER

Your approach is fine, if it doesn't work, it must be due to a typo.

0
mi_mo On

I had a similar problem for exclude :

net.minidev:json-smart

dependency for security issue that it have in version 2.3 .

you should install: Maven dependency helper plugin in intellij , after install it you can see your dependencies and sub dependencies of them like below(a new tab added in bottom of pom file as i mention it):

enter image description here

then you can see your dependencies conflicts, versions and etc. if you do right-click on each dependency , you can exclude specific dependency .

I hope this text has been useful to you.