Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to properly remove a dependency in a Maven project

I have a Java Maven project where I have some dependencies defined in the pom.xml file. Recently I decided to move from Junit to TestNG so I deleted the Junit dependency from my pom.xml and added the TestNG one.

I was expecting to see the Junit jar library disappear from the Maven Dependencies folder as a part of the process but that didn't happen. I can still see the jar file in the dependencies folder and it is still being used by my test cases.

I can see TestNG jar is there as well but it's not being used. I can change it manually of course but that wasn't my intention.

Am I doing something wrong are there any additional steps that I missed that will allow me to remove the old dependency?

like image 604
Eugene S Avatar asked Dec 06 '25 09:12

Eugene S


1 Answers

The following applies for the global .m2 folder where maven dependencies can be downloaded and is common to your maven projects.

the .m2 folder will not clean by itself as those dependencies could be used in another project so its wrong assumption that replacing a dependency in a a pom file will automatically remove from your repo.

you can look at the depedency plugin and run the following

mvn dependency:purge-local-repository

or

mvn dependency:purge-local-repository -DreResolve=false
like image 110
Frederic Henri Avatar answered Dec 08 '25 01:12

Frederic Henri



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!