What is the scope provided ?
Suppose a jar needed to compile your code, but jar is present in the production library library collection. Then you do not need to pack a jar with project archives. To support this requirement, Maven has an area called provided . If you declare any jar dependency as provided , then this jar will be present in your class path at compile time, but will not be packaged in your project archive.
provided area is very useful, especially in web applications. For example, servlet-api.jar must be present in your class path to compile your project, but you do not need this to package the servlet-api.jar file with war . With the scope provided , this requirement can be achieved.
There is no framework defined in the Gradle java plugin named provided . Also not in war or android plugins. If you want to use the provided scope in your project, you must define it in your build.gradle file. Below is the code snippet for declaring the provided scope in gradle:
configurations { provided } sourceSets { main { compileClasspath += configurations.provided } }
Now, your second question:
What is the difference between the provided and working dependency environment in Gradle?
To answer this question, I will first define the compile dependency. compile dependencies are dependencies that are needed to compile your code. Now imagine that if your code uses a library called X , then you should declare X as your compile-time dependency. Also imagine that X uses another Y library internally, and you declared Y as your runtime dependency.
At compile time, Gradle will add X to your classpath, but not Y Since compilation does not require Y But it will collect both X and Y with your project archive, since both X and Y needed to run the project archive in the production environment. Typically, all dependencies needed in a production environment are known as runtime dependencies.
Gradle's official documentation says runtime depends on the dependencies required by production classes at runtime. By default, compile time dependencies are also included. "
Now, if you have known this for a long time, you already know that provided is a compile dependency that we donβt want to be present depending on runtime (in principle, we donβt want this package with the project archive).
The following is an example of the scope provided and runtime . Here, compile refers to dependencies that are needed to compile a project, and non-compile refers to dependencies that are not required to compile a project.
