dev-null dev-null - 7 days ago 5
Java Question

'Provided' dependency in Gradle

I have

build.gradle
in fron of me and there are some dependencies declared as
provided
but in documentation I do not see this dependency scope.

dependencies {
compile("org.springframework.boot:spring-boot-starter-web:1.2.4.RELEASE")
....

provided 'backport-util-concurrent:backport-util-concurrent:3.1'
provided 'org.javolution:javolution:5.5.1@jar
....
}


Is this provided by a plugin? If so how do I found out which plugin this belongs to?

What is the difference between
provided
and
runtime
dependency scope in Gradle?

Answer

There is no Scope defined in Gradle java plugin named provided. Also not in war or android plugins. If you see that any project is using 'provided' scope, and used any of these plugins only, then the scope must be defined in the configuration in your build.gradle.

Now, your second question:

What is the difference between provided and runtime dependency scope in Gradle?

So you already know that provided is not a basic scope in java plugin, but runtime is a basic scope in java plugin.

runtime dependency is defined in java plugin as "The dependencies required by the production classes at runtime. By default, also includes the compile time dependencies." in gradle official documentation.

To understand that, first you have to know what compile dependency is. compile dependencies are dependencies, those are directly used by your codes.

For example if your code uses a library named a then you must declare a as your compile time dependency. Now if a uses another library b internally. then you have to declare b as your runtime dependency. But to run the program you will need both a and b at runtime, that is why, by default compile time dependencies are also included in runtime dependency.

Comments