In build.gradle
we can define variables like:
def libVersion='someVersion'
We can override properties in command line with -PlibVersion=otherVersion
Unfortunately it seems this command line option does not affect local variables defined in build.gradle
. Is there a way to override these from command line? Please note that for some reasons i do not want to create settings.gradle
nor gradle.properties
files.
Gradle can handle the build file using gradle command. This command will compile each task in such an order that they are listed and execute each task along with the dependencies using different options.
To run a Gradle command, open a command window on the project folder and enter the Gradle command. Gradle commands look like this: On Windows: gradlew <task1> <task2> … e.g. gradlew clean allTests.
Here's an example:
ext.greeting = project.hasProperty('greeting') ? project.getProperty('greeting') : 'hello' task greet << { println greeting }
If you run gradle greet
, it will print hello
.
If you run gradle -Pgreeting=welcome greet
, it will print welcome
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With