This should be the simplest of questions but I am having a problem accessing System variable from a Gradle test task. There must be a typo in what I am doing since I am convinced this syntax is correct but it doesn't work. I am hoping someone can help me identify the problem with this code snippet below?
// my gradle build says the following line is a deprecated method
//systemProperties = System.getProperties()
// this line always returns 1 on a multiprocessor system
println 'NUMBER_OF_PROCESSORS is ' +
System.getProperty( "NUMBER_OF_PROCESSORS", "1" )
// this line also always returns the default for TMP var
println 'TMP is ' + System.getProperty( "TMP", "C:\\Temp" )
NOTE: I also asked the question here but since its a closed thread I am unsure if I will get an answer there. Also, I have read the doc thoroughly but it didn't help.
I tried these and they also fail:
test {
println ""
ENV = System.getProperties()
println "TMP is " + ENV['TMP']
println ""
}
task testa(Type:Test) {
println ""
println "HOMEPATH = " + System.getProperty( "HOMEPATH", "defaultpath" )
println "TMP = " + System.getProperty( "TMP", "defaulttmp" )
println ""
}
task testb(Type:Test) {
println ""
println "HOMEPATH = " + System.properties['HOMEPATH']
println "TMP = " + System.properties['TMP']
println ""
}
task testc(Type:Test) {
// pass a arg to this test like -PMYARG=anything
println ""
println "Parg = " + System.properties['MYARG']
println ""
}
testWorks {
println ""
ENV['ok'] = "good to go"
println "this test is " + ENV['ok']
println ""
}
To make the Gradle JVM's system properties available to tests, you can do:
test {
systemProperties = System.properties
}
Or, if you have declared additional Test
tasks:
tasks.withType(Test) {
systemProperties = System.properties
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With