如何在gradle.properties文件中指定gradle项目属性?

如何在gradle.properties文件中指定gradle项目属性?

问题描述:

是否可以在 gradle.properties 文件中指定项目属性,例如名称,以便可以从 build.gradle 访问它们通过使用 project.name

Is it possible to specify project properties such as name in gradle.properties file so will be possible to access them from build.gradle by using project.name?

我没有运气尝试过:

name=some
project.name=some
org.gradle.project.name=some


您可以做到。

例如,在您的 root gradle.properties 文件,您可以拥有:

For example in your root gradle.properties file you can have:

VERSION_NAME=2.0.2

然后在build.gradle文件中(位于 root 文件夹),例如:

Then in your build.gradle file (in the root folder) you can have for example:

allprojects {
    version = VERSION_NAME
}

如果您想在模块中使用它 build.gradle 文件,您可以拥有:

If you would like to use it in your module build.gradle file you can have:

android {

    defaultConfig {
        versionName project.VERSION_NAME  
    }
}