Show List

Gradle properties and system properties

Gradle properties and system properties are used to store and manage configuration information in a Gradle project. They allow you to customize the behavior of the build process and provide a way to pass information to the build script.

Gradle properties are defined in the build.gradle file and can be used to store information such as the version of a library, the path to a resource, or a custom configuration setting. Here is an example of a Gradle property:

bash
Copy code
ext { guavaVersion = '28.1-jre' } dependencies { implementation "com.google.guava:guava:$guavaVersion" }

In this example, the guavaVersion property is defined and used in the dependencies section to specify the version of the Guava library that is required by the project. By using a property, you can easily change the version of the library without having to modify multiple lines of code.

System properties, on the other hand, are properties that are set at the operating system level and are available to all applications running on the system. System properties can be passed to Gradle as command-line arguments, and can be used to customize the behavior of the build process. Here is an example of a system property:

bash
Copy code
./gradlew build -DguavaVersion=28.1-jre

In this example, the guavaVersion system property is passed to Gradle when running the build task. The value of the system property can be accessed in the build.gradle file using the System.getProperty() method:

bash
Copy code
ext { guavaVersion = System.getProperty('guavaVersion', '28.1-jre') } dependencies { implementation "com.google.guava:guava:$guavaVersion" }

By using system properties, you can customize the behavior of the build process without having to modify the build.gradle file, making it easier to switch between different configurations and environments.

In summary, Gradle properties and system properties provide a flexible way to manage configuration information in a Gradle project, making it easier to customize the build process and switch between different configurations and environments.


    Leave a Comment


  • captcha text