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.