JavaExec strips double-quotes from property values on Windows


(Sebastian Schuberth) #1

It seems that on Windows the JavaExec task does not properly handle property values that contain double-quotes. For example for the following

task runApp(type: JavaExec) {
    classpath = sourceSets.main.runtimeClasspath

    main = 'net.rubygrapefruit.platform.test.Main'

    systemProperties['json'] = '{"enabled":true}'

    println getAllJvmArgs()
}

the println still properly shows [-Djson={"enabled":true}, ... but the class being run returns {enabled:true} (no quotes around “enabled”) for System.getProperty("json").

Note that this only happens on Windows. On Linux I do not observe this behavior.


(Lance Java) #2

This is a feature of the Properties class. You’ll need to escape quotes if you want them included

Eg
systemProperties['json'] = '{\\"enabled\\":true}'

Or using slashy strings
systemProperties['json'] = /{\"enabled\":true}/


(Sebastian Schuberth) #3

Where exactly is this behavior documented? In the Properties docs the only relevant sentence I find is “Escapes are not necessary for single and double quotes”, so escaping should not be necessary. Also, why am I seeing this behavior only on Windows?