I am having cross-platform issues when calling a Gradle JavaExec task from Python. One sub-project has an application to generate some output and it accepts command line arguments to do so.
Gradle task:
task run(type: JavaExec) {
main = 'generator.myGenerator'
classpath = sourceSets.main.runtimeClasspath
if (System.getProperty("exec.args") != null) {
args System.getProperty("exec.args").split()
}
}
./gradlew run -Dexec.args="--minBound 5 --maxBound 8"
args = ('-Dexec.args=\"--minBound\ ' + str(min_bound) +
'\ --maxBound\ ' + str(max_bound) + '\"')
subprocess.check_call(['./gradlew', 'run', args])
:generator:run
maxBound\ is not a recognized option
After some tinkering, I noticed that by putting all arguments in a list and turning them into a string with
args = '\ '.join(argList)
would work on Cygwin and
args = ' '.join(argList)
would work on Linux. However, I did not find a nice platform-independent way for this solution without detecting which OS was being used. Instead, I found a solution based on raw strings that works well on both Cygwin and Linux.
argRaw = r"-Dexec.args= --minBound {} --maxBound {}"
args = argRaw.format(min_bound, max_bound)