Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Default value for a $PROPERTY in Gradle

How can I specify a default value for this simple build.gradle script:

println "Hello $build_version"  

So that I don't get the error:

A problem occurred evaluating root project 'hello_gradle'. > Could not find property '$build_version' on root project 'hello_gradle'. 

I tried some of the operators, checking for nulls etc, but I think just the reference to the property makes it fail. I could fix that by always providing the property, but that's less than ideal.

gradle -Pbuild_version=World 
like image 834
Zero Distraction Avatar asked Dec 20 '13 01:12

Zero Distraction


People also ask

How do you pass JVM arguments in Gradle?

Try to use ./gradlew -Dorg. gradle. jvmargs=-Xmx16g wrapper , pay attention on -D , this marks the property to be passed to gradle and jvm. Using -P a property is passed as gradle project property.

How do I pass system properties to Gradle build?

Using the -D command-line option, you can pass a system property to the JVM which runs Gradle. The -D option of the gradle command has the same effect as the -D option of the java command. You can also set system properties in gradle. properties files with the prefix systemProp.


1 Answers

if (!project.hasProperty("build_version")) {     ext.build_version = "1.0" } 
like image 96
Peter Niederwieser Avatar answered Oct 11 '22 09:10

Peter Niederwieser