2

I'm using a maven dependency that already depends on google's gson library. I'm fine with the version that comes with it.

Which of this is a good practice?

  1. Include google gson library my pom.xml explicitly ignoring the fact that its already included in another dependency?

  2. Use the google gson library that comes as a part of the other maven dependency, that is, do not explicitly include it in the pom.xml?

EDIT: I want use google gson library directly also in my code.

Neeraj Krishna
  • 1,527
  • 2
  • 16
  • 22
  • 2
    First one. Means each dependency you are using directly declare it directly in your pom file... – khmarbaise Nov 07 '17 at 12:57
  • 1
    i would say as long as you yourself do not need google gson library, you should not include it in POM. as soona s you want to use any functionality of it in your code, put it in the POM – XtremeBaumer Nov 07 '17 at 12:57
  • Unless you have very explicity requirements - typically due to new versions not being usable to you - you should not in any way concern yourself with the transient dependencies. Keep it simple. List those _you_ need and let Maven sort out the rest. – Thorbjørn Ravn Andersen Nov 07 '17 at 13:23

1 Answers1

-1

With maven you have this horrible version drama. Maven uses the dependency version that comes first. So if you wan't to be sure to have the correct version you must include the lib in your pom.xml before the other lib (or exclude it there).

If it does not matter which version it is take the ones from the dependency. There is nothing against it except at some point in the future when you update the third party lib and gson is removed. (but that is another problem?!)