如何在gradle.properties文件中指定gradle项目属性? [英] How can I specify gradle project properties in gradle.properties file?

查看:584
本文介绍了如何在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  
    }
}

这篇关于如何在gradle.properties文件中指定gradle项目属性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆