Could not find method environment() for arguments


(Praveen) #1

Hello Guys!
Need help in below issue.
I’m trying to pass environment variables through gradle check
ex: gradle check -Dpostgres.host=“someipaddress”
If I pass the above way, my code works. But the requirement is, if I dont pass any value and just say gradle check, it should take the default value which is not happening.
Below is my piece of code in build.gradle file.
test {
String pdb = System.properties.getProperty(“postgres.host”, “127.0.0.1”)
environment “spring.datasource.url”, “jdbc:postgresql://$pdb:5432/mydb”
}
Here 127.0.0.1 is the default value. But if I execute gradle check, pdb is not being set to 127.0.0.1
So I executed build file separately and got error “could not find method environment() for arguments”
Am I doing anything wrong here? Any help would be highly appreciated.


(Praveen) #2

Hello people. Hope someone helps me here.


(Fred Curts) #3

To clear up a misconception, -D sets a system property for the entire Gradle invocation, not for a particular task. Nevertheless, I don’t see anything wrong with your code. (System.properties.getProperty() can be simplified to System.getProperty()). Are you sure you are drawing the right conclusions? Perhaps you have other Test tasks besides test?


(Praveen) #4

Thanks for your response. Unfortunately, this code is not working. Could you please suggest me how to override certain values of application.properties dynamically ?