1

enter image description here

As per image from Maven's complete reference, when a direct dependencies scope is 'compile' and transitive dependency's scope is 'provided', transitive dependencies are ignored.

My question is, if a direct dependency class extends a class from this transitive dependency compilation of my project will fail, since at compile time 'javac' will look for class extended by direct dependency from transitive dependency and won't find it in compile time classpath, as maven ignored it.

Basically that is the reason why transitive dependency scope is compile instead of run-time when direct dependency is compile, why same rule is not considered when transitive dependency scope is provided?

John
  • 371
  • 3
  • 11

1 Answers1

2
  1. compile needs to be transitive and your example of inheritance is one reason for that. Of course, you usually do not need all transitive compile dependencies for compilation but better safe than sorry.

  2. provided is not transitive. My interpretation is as follows: provided means that the container/platform provides you the desired artifacts. What is provided and what not is container dependent. It makes little sense to mark a dependency of a library as provided if you do not know the container it will run on. So it makes more sense to "sort" the dependencies on the level of the "deployable unit", e.g. the war or ear.

J Fabian Meier
  • 33,516
  • 10
  • 64
  • 142