Configuration name | Role | Consumable? | Resolvable? | Description |
---|---|---|---|---|
| Declaring API dependencies | no | no | This is where you should declare dependencies which are transitively exported to consumers, for compile. |
| Declaring implementation dependencies | no | no | This is where you should declare dependencies which are purely internal and not meant to be exposed to consumers. |
| Declaring compile only dependencies | no | no | This is where you should declare dependencies which are only required at compile time, but should not leak into the runtime. This typically includes dependencies which are shaded when found at runtime. |
| Declaring runtime dependencies | no | no | This is where you should declare dependencies which are only required at runtime, and not at compile time. |
| Test dependencies | no | no | This is where you should declare dependencies which are used to compile tests. |
| Declaring test compile only dependencies | no | no | This is where you should declare dependencies which are only required at test compile time, but should not leak into the runtime. This typically includes dependencies which are shaded when found at runtime. |
| Declaring test runtime dependencies | no | no | This is where you should declare dependencies which are only required at test runtime, and not at test compile time. |
看起来这三个关键字的作用是一样的,那么,他们到底有什么区别呢?
api和compile关键字作用效果是一样的,使用时可以互相替换。实际上,api关键字是用来替代compile关键字的,因为compile关键字将来会被弃用。在高版本的gradle,使用compile关键字会报错并提示使用api关键字代替 。api或compile关键字引用的包对于其他module来说是可见的,而implementation关键字引用的包对于其他module来说是不可见的。
https://docs.gradle.org/current/userguide/java_library_plugin.html