Command Line
To pass project properties via the command line in Gradle, you can use the -P
flag followed by the property name and value. This allows you to override or define properties at runtime without modifying the gradle.properties
file.
Example of Passing a Project Property via the Command Line:
You can pass the version
property like this:
Glass thought Sandbox Snapshot
Command to reproduce:
gt.sandbox.checkout.commit d043a3a \
&& cd "${GT_SANDBOX_REPO}" \
&& cmd.run.announce "./gradlew go -Pversion=9.9"
Recorded output of command:
> Task :lib:go
Project version: 9.9
BUILD SUCCESSFUL in 360ms
1 actionable task: 1 executed
This will override any version
property defined in the gradle.properties
file and set the version for this specific build invocation.
Key Points:
- Use
-PpropertyName=value
to pass properties via the command line. - Properties passed this way override those defined in the
gradle.properties
file. - Access the property in your build script using
project.propertyName
.
Backlinks