android build.gradle 群有什么用?

android build.gradle what is group used for?

检查 build.gradle 并且项目本身有一个名为 "group" 的变量。在代码中,我继承了应用程序 ID 的集合,但是组的用途是什么?

gradle documentation 它指出:

void setGroup(Object group) Sets the group of this project.

更新:据我所知 here 看来群组是用于将任务分组在一起的。

该组实际上是一个命名空间,用于标识构建生成的一个或多个工件。例如,当您有这样的依赖项时:

dependencies {
    compile 'org.hibernate:hibernate-core:3.6.7.Final'
}

org.hibernate 是组(或 Maven 说法中的 groupId)。因此,如果您的构建生成一个发布到存储库的 JAR 文件,它会在您在构建文件中指定的组下发布:

group = "org.example"

我不知道这个小组在发布工件之外是否有意义。我只将它用于 JAR 库。

@Peter Ledbrook 对原始问题的回答是正确的。由于我无法编辑上面的答案,我会写一个独立的答案来回答@Faraz 并提供一些额外的上下文。

下面是如何在任务本身打印项目组的说明。

Group property is assigned to the project. So first you have to access project instance from the task. Then you access direct group property of the project. Don't confuse it with the group property of the task,它具有另一种语义,用于将 Gradle 属性分组到特定任务的类别中,以便于导航它们。

在任务本身中,您可以使用 Groovy 语法支持的简单 string interpolation 打印 属性。

打印项目组 属性 的示例任务。

group 'com.rivancic.project.group'

task printProjectGroup {
    doLast {
        logger.info("Project group in which task is being executed: ${project.group}")
    }
}