Junior — Middle
What are the main keywords used for declaring dependencies in a Gradle file?
sobes.tech AI
Answer from AI
In the Gradle file, the following main keywords (configurations) are used to declare dependencies:
implementation— the main configuration for adding dependencies needed for compiling and running the application, but not exported further.api— used in library modules to make dependencies available to consumers of this library.compileOnly— dependencies available only at compile time, not included in the final artifact.runtimeOnly— dependencies needed only at runtime, not during compilation.testImplementation— dependencies used only in tests.
Example:
dependencies {
implementation 'com.squareup.retrofit2:retrofit:2.9.0'
testImplementation 'junit:junit:4.13.2'
}
Previously, keywords like compile, provided, and others were used, but they are considered deprecated and replaced with the more precise configurations listed above.