1

I have two dependencies in my pom.xml:

    <dependency>
        <groupId>org.apache.httpcomponents</groupId>
        <artifactId>httpcore</artifactId>
        <version>4.0-beta1</version>
    </dependency>
    <dependency>
        <groupId>org.apache.httpcomponents</groupId>
        <artifactId>httpcore-nio</artifactId>
        <version>4.0-beta1</version>
    </dependency>

httpcore-nio directly requiers httpcore so i do not need the dependency and could remove it.

Is there a way to remove or at least detect, unesseary dependencies automaticaly, for all dependencies, and their coressponding dependency tree?

Jens
  • 67,715
  • 15
  • 98
  • 113
TAMSG
  • 121
  • 1
  • 6
  • Does this answer your question? [Is there a simple way to remove unused dependencies from a maven pom.xml?](https://stackoverflow.com/questions/1517611/is-there-a-simple-way-to-remove-unused-dependencies-from-a-maven-pom-xml) – Joe Mar 01 '22 at 11:02
  • This is a diffrent question, I don't care whether or not it is used by my java code, I do care however, whether or not it is obsolete, by the pom indirect dependencies, itself. Thanks for the hint anyway, it will be a good second step. – TAMSG Mar 01 '22 at 11:58
  • You could use `mvn dependency:tree` to see the dependency tree and then write a script that compares any top level element with all lover level once. I feel like there should be a better way. – TAMSG Mar 01 '22 at 12:04
  • 2
    If you use something in your source code, it is best practise to declare it explicitly in your POM. This allows you to control the version and also avoids bad surprises if you update your dependencies and suddenly, some transitive dependency is gone. – J Fabian Meier Mar 01 '22 at 13:04
  • @JFabianMeier I agree with you, but let me assure you I considered it. I rather take the risk of a surprise in the future and clean up the mess that is the current state. Furthermore, I think it is easier to tell if something is needed when suddenly something does not run anymore, then finding out something was not needed in the first place. I do not recommend anyone to do this, i.e. in their pipeline but being able to detect i,t is nice, the reaction may differ ofc. – TAMSG Mar 01 '22 at 13:11
  • 1
    Sorry, but I do not give advice how to circumvent best practises without an urgent need. These questions/answers are read by a lot of people, and it is easy to put a beginner on a wrong path. – J Fabian Meier Mar 01 '22 at 14:28
  • The first thing you really need is having unit/integration tests. If that is the case you can simply try to remove a dependency you might think you don't need. And I recommend also the comments by @JFabianMeier about declaration. – khmarbaise Mar 02 '22 at 20:00

0 Answers0