I am using android studio and in project structure -> dependencies tab following options i can see:
my question: what is the difference between compile, testCompile and provided in gradle dependency
Fortunately, the implementation dependency configuration provides the same functionality as compile. You should always use implementation rather than compile for dependencies, as compile is now deprecated or removed in the case of Gradle 7+.
The compileOnly configuration is used to itemize a dependency that you need to compile your code, same as compile above. The difference is that packages your java code use from a compileOnly dependency will not be listed as Import-Package manifest entries.
Here, compile refers to the dependencies that are required to compile the project and non-compile refers to the dependencies that are not required for project compilation. The compileOnly configuration is the closest option to mavens "provided" scope, but it is not a true "only at compile time" configuration.
For example the testImplementation configuration extends the implementation configuration. The configuration hierarchy has a practical purpose: compiling tests requires the dependencies of the source code under test on top of the dependencies needed write the test class.
compile
is the group of dependencies you need to build your application while testCompile
is a group of dependencies that you need only for testing.
Look for instance at this build.gradle
(taken from here)
apply plugin: 'java' repositories { mavenCentral() } dependencies { compile group: 'org.hibernate', name: 'hibernate-core', version: '3.6.7.Final' testCompile group: 'junit', name: 'junit', version: '4.+' }
This specifies that hibernate-core
is needed to build your code but junit
(a testing framework) is needed just for testing. Since it's not needed at runtime, it's not going to be included in the released package.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With