Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Override property in build.gradle from the command line

Tags:

gradle

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.

like image 870
WonderCsabo Avatar asked Aug 30 '14 12:08

WonderCsabo


People also ask

What is the command for Gradle build?

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.

How do I run Gradle from command prompt?

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.


1 Answers

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.

like image 167
JB Nizet Avatar answered Sep 20 '22 04:09

JB Nizet