Reputation: 1023
I have this really strange behavior in Gradle and I cannot find a way out of it. In my gradle.properties
file, I am using this checking condition:
//gradle.properties
if ( "${System.Property['DATABASE_DIR']}".compareTo('swdb') == 0 ) {
PROJECT_DATABASE_PATH=../database/swdb/include
}
else {
PROJECT_DATABASE_PATH=../database/include/
}
I created a new task called printProperties
and it looks like this.
//build.gradle
task printProperties {
println "${System.properties['DATABASE_DIR']}".compareTo('swdb') == 0
println PROJECT_DATABASE_PATH
}
I get the following output when I run the printProperties
task.
$gradle printProperties -DDATABASE_DIR=swdb
true
../database/include/
:printProperties UP-TO-DATE
BUILD SUCCESSFUL
Total time: 1.07 secs
It is really strange that the task prints true but the gradle.properties
file does not evaluate the same condition correctly. Could anybody help me with this?
Upvotes: 0
Views: 7748
Reputation: 3579
Your code shall take place in a init.gradle
script.
You can find documentation here : https://docs.gradle.org/current/userguide/init_scripts.html
gradle.properties
file is only for key=value pairs
Upvotes: 5