gradle 转换 API 范围的定义

Definitions for gradle Transform API scopes

Gradle 的 transform API 定义了多个范围。但是,关于每个范围的含义的文档很少。有人知道吗?

/**
 * The scope of the content.
 *
 * <p/>
 * This indicates what the content represents, so that Transforms can apply to only part(s)
 * of the classes or resources that the build manipulates.
 */
enum Scope {
    /** Only the project content */
    PROJECT(0x01),
    /** Only the project's local dependencies (local jars) */
    PROJECT_LOCAL_DEPS(0x02),
    /** Only the sub-projects. */
    SUB_PROJECTS(0x04),
    /** Only the sub-projects's local dependencies (local jars). */
    SUB_PROJECTS_LOCAL_DEPS(0x08),
    /** Only the external libraries */
    EXTERNAL_LIBRARIES(0x10),
    /** Code that is being tested by the current variant, including dependencies */
    TESTED_CODE(0x20),
    /** Local or remote dependencies that are provided-only */
    PROVIDED_ONLY(0x40);

    private final int value;

    Scope(int value) {
        this.value = value;
    }

    public int getValue() {
        return value;
    }
}

鉴于 Android N 源代码尚未发布,因此没有太多好的示例可供阅读。到目前为止,我发现的最好的是 realm-java,它包含几个变压器。

尝试了多种不同的示波器组合。并确定了以下内容;

  • PROJECT:此范围表示目标 gradle 模块。
  • PROJECT_LOCAL_DEPS: 目标模块 "libs" 文件夹中的依赖项
  • SUB_PROJECTS:同一个 android studio 项目中的依赖项,例如其他 gradle 模块。例如,这个不允许让我们分析毕加索的class文件。
  • SUB_PROJECTS_LOCAL_DEPS:本地 "libs" 同一 android 工作室项目中依赖项的文件。
  • EXTERNAL_LIBRARIES:从 maven 中提取的库。例如,确实允许我们分析毕加索的class文件。