What's the difference between implementation and compile in Gradle?

前端 未结 9 1579
北荒
北荒 2020-11-22 03:01

After updating to Android Studio 3.0 and creating a new project, I noticed that in build.gradle there is a new way to add new dependencies instead of comp

9条回答
  •  天涯浪人
    2020-11-22 03:28

    +--------------------+----------------------+-------------+--------------+-----------------------------------------+
    | Name               | Role                 | Consumable? | Resolveable? | Description                             |
    +--------------------+----------------------+-------------+--------------+-----------------------------------------+
    | api                | Declaring            |      no     |      no      | This is where you should declare        |
    |                    | API                  |             |              | dependencies which are transitively     |
    |                    | dependencies         |             |              | exported to consumers, for compile.     |
    +--------------------+----------------------+-------------+--------------+-----------------------------------------+
    | implementation     | Declaring            |      no     |      no      | This is where you should                |
    |                    | implementation       |             |              | declare dependencies which are          |
    |                    | dependencies         |             |              | purely internal and not                 |
    |                    |                      |             |              | meant to be exposed to consumers.       |
    +--------------------+----------------------+-------------+--------------+-----------------------------------------+
    | compileOnly        | Declaring compile    |     yes     |      yes     | This is where you should                |
    |                    | only                 |             |              | declare dependencies                    |
    |                    | 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. |
    +--------------------+----------------------+-------------+--------------+-----------------------------------------+
    | runtimeOnly        | Declaring            |      no     |      no      | This is where you should                |
    |                    | runtime              |             |              | declare dependencies which              |
    |                    | dependencies         |             |              | are only required at runtime,           |
    |                    |                      |             |              | and not at compile time.                |
    +--------------------+----------------------+-------------+--------------+-----------------------------------------+
    | testImplementation | Test dependencies    |      no     |      no      | This is where you                       |
    |                    |                      |             |              | should declare dependencies             |
    |                    |                      |             |              | which are used to compile tests.        |
    +--------------------+----------------------+-------------+--------------+-----------------------------------------+
    | testCompileOnly    | Declaring test       |     yes     |      yes     | This is where you should                |
    |                    | compile only         |             |              | declare dependencies                    |
    |                    | 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. |
    +--------------------+----------------------+-------------+--------------+-----------------------------------------+
    | testRuntimeOnly    | Declaring test       |      no     |      no      | This is where you should                |
    |                    | runtime dependencies |             |              | declare dependencies which              |
    |                    |                      |             |              | are only required at test               |
    |                    |                      |             |              | runtime, and not at test compile time.  |
    +--------------------+----------------------+-------------+--------------+-----------------------------------------+
    

提交回复
热议问题