Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to assign default values for ext based properties in gradle

Tags:

gradle

groovy

I am working on a gradle plugin with a task where it accesses the extra params using the project object itself like

project.extraParam1
project.extraParam2

Now I can use this plugin from another project and pass the parameters in the build.gradle file as

ext {
  extraParam1 value1
  extraParam2 value2
}

I mean I apply this plugin in another project's build.gradle. Define the ext parameters and call the plugin task and it works. The task is able to access the extra properties. However, I want to set some default values to these, so that even though the project which is using the plugin doesn't define the ext parameter, it has some default values and works for default values.

like image 212
user12331 Avatar asked Oct 20 '25 14:10

user12331


1 Answers

In your plugin, you can do something like that :

def extraParam1 = project.hasProperty('extraParam1') ? project.extraParam1 : 'default value'
like image 170
ToYonos Avatar answered Oct 23 '25 07:10

ToYonos



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!