Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is a transitive Maven dependency?

This question is about to clarify what exactly a transitive dependency is and how it works at very high level in Maven.

My definition: in a dependency tree like A --> B --> C, C is a transitive dependency for A. Assume B has scope compile within A.

If C has scope compile within B, then declaring B as dependency of A suffices to build A with Maven. But if C has scope provided within B then, when Maven builds A, the building will not automatically compile A against C unless A declares C among its dependencies.

Is this correct?

like image 703
Johan Avatar asked Jan 18 '17 17:01

Johan


People also ask

What is transitive dependency in spring?

transitive dependency that is managed by the parent POM, just add a. version property for that dependency. For this rule to work the parent. POM has to define version properties for all the dependencies that it. manages (the spring-boot-starter-parent does this).

What is direct and transitive dependency?

In a computer program a direct dependency is functionality exported by a library, or API, or any software component that is referenced directly by the program itself. A transitive dependency is any dependency that is induced by the components that the program references directly.

How do you resolve transitive dependencies?

Once you identify your package to be fixed using any of the above methods, to fix the transitive dependency, you must add a dependency to the updated version of the vulnerable package by adding it to the . csproj file. i.e such a vulnerable package needs to be made a direct dependency of your main project.


1 Answers

Your assumption is correct.

There are two types of Maven dependencies:

  • Direct: These are dependencies defined in your pom.xml file under the <dependencies/> section.

  • Transitive: These are dependencies that are dependencies of your direct dependencies.

Dependencies with provided scope are meant to:

  • Either be excluded from the final artifact (for example, for war files you would not want to include servlet-api, servlet-jsp, etc)
  • Or overriden -- where the project that inherits these defines a version and/or overrides the scope
like image 186
carlspring Avatar answered Sep 30 '22 21:09

carlspring