I am having trouble getting simple -P values to work. I have a multi-module build, so maybe the root/sub project comes into play, but what I have is this:
in the root build.gradle I have the following abbreviated code:
subprojects { subProject ->
…
subProject.tasks.withType( Test.class ).all { task ->
…
printf 'checking `db` setting wrt applying databases.gradle overrides\n'
if ( hasProperty( 'db' ) ) {
final String db = property( 'db' )
printf 'Encountered db setting : %s', db
dbBundle[db].each { entry->
println ' [' + entry.key + '] -> [' + entry.value + ']'
}
task.systemProperties.putAll( dbBundle[db] );
}
}
}
I then run the following command:
…/gradlew -Pdb=oracle test --tests “org.hibernate.test.hql.ASTParserLoadingTest”
but I only get the following output and for sure the test sys props do not contain these values:
checking db setting wrt applying databases.gradle overrides
checking db setting wrt applying databases.gradle overrides
checking db setting wrt applying databases.gradle overrides
checking db setting wrt applying databases.gradle overrides
checking db setting wrt applying databases.gradle overrides
…
(I’ve tried both -P and -D but no difference)
Why is hasProperty not picking up these -P/-D options?
delegate corresponds to a third party object where methods calls or properties are resolved whenever the receiver of the message is not defined
By default, the delegate is set to owner
tasks.withType(Test).all { task ->
println "Configuration closure delegate is: ${delegate}"
println "Configuration closure owner is: ${owner}"
println "Configuration closure this is: ${this}"
if (hasProperty('db')) {
println "Property db is set, working with $task"
}
}
If you run this, it will print:
Configuration closure delegate is: task ':test'
Configuration closure owner is: DynamicObject for task ':test'
Configuration closure this is: root project 'foo'
When using -P flag, you set project properties. But the hasProperty is sent to a task object, not your project object. To solve your issue, you can use: