1

I have searched all over the net what's the difference between provided and compile scope in maven but everywhere the answer was during provided scope dependency is provided by JDK or a container at run time and not packaged in war and when scope is compile it is packaged in the war.

But no one tells about how this behaves during compilation, because if scope is 'compile' then ok , we know that same dependency which is present during compilation is packaged in war and same is used during run time, so no problem. But if dependency is provided then who provides it during compilation and whether it is same(version) with when provided by container.

tempEngineer
  • 223
  • 1
  • 3
  • 13
  • *"who provides it during compilation?"* Maven, since it is setting up the classpath when it does the compilation. --- Paraphrased: *"is it same version provided by container?"* Only if your POM specifies the same version as provided by container. – Andreas May 16 '17 at 10:48
  • A common strategy to prevent differences between compile time classpaths and runtime classpaths is to bundle everything with the application - including the container itself. For example Spring Boot automates that for you. Its a tidy way to create a 100% self-contained package. – Gimby May 16 '17 at 10:53
  • then why is it that sometimes providing scope as 'provided' works but 'compile' not works?. Because by making scope as 'compile' we are ensuring that that dependency will be packaged to war file and same will be used during runtime, so ideally there shouldn't be a problem or error. – tempEngineer May 17 '17 at 09:37

0 Answers0