📜  gradleproperties (1)

📅  最后修改于: 2023-12-03 15:15:25.421000             🧑  作者: Mango

Gradle Properties

Gradle properties is a file where we can store and manage our project-specific values or custom variables. It is also known as a property file or configuration file in software development. Gradle uses a properties file format that is similar to Java’s properties file format.

How to use Gradle Properties

Gradle allows you to create, define and use variables in your project’s build files. You can create and use variables in several ways.

1. Define variables in gradle.properties file

In your project directory, create a file named gradle.properties. You can define your variables in this file in the following format:

variableName=variableValue

For example:

appName=MyAwesomeApp
appVersion=1.0.0

These variables can be accessed and used throughout the Gradle build script.

2. Define variables in build.gradle file

You can also define variables inside build.gradle file like this:

ext {
    appName = "MyAwesomeApp"
    appVersion = "1.0.0"
}

These variables can also be accessed and used throughout the Gradle build script.

3. Use variables in build.gradle file

To use the defined variables in your build.gradle file, you just need to reference them by their name like this:

task printAppName {
    doLast {
        println appName
    }
}
Conclusion

In conclusion, Gradle properties are a useful way to store and manage project-specific values or custom variables. It helps in simplifying your Gradle build scripts and provides a way to reuse values across different parts of the project.