user12331
user12331

Reputation: 518

How to assign default values for ext based properties in gradle

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.

Upvotes: 4

Views: 4089

Answers (1)

ToYonos
ToYonos

Reputation: 16833

In your plugin, you can do something like that :

def extraParam1 = project.hasProperty('extraParam1') ? project.extraParam1 : 'default value'

Upvotes: 5

Related Questions