JavaExec and quotes on Windows

I ran into trouble with a ‘JavaExec’ these days. The tasks was rather straight-forward, but one argument contained quotation marks.

Consider this simple echo service:

package some.echo

class Service {

public static void main(String[] args) {

args.each { println it }

}

}

Compiling and calling the service with these two tasks gives the following output.

task a(type: JavaExec) {

classpath = project.files(

project.sourceSets.main.output,

project.configurations.runtime

)

main = “some.echo.Service”

args = [ “the “argu” ment”]

}

task b(type: JavaExec) {

classpath = project.files(

project.sourceSets.main.output,

project.configurations.runtime

)

main = “some.echo.Service”

args = [ “the ““argu”” ment” ]

}

Note the double quotation marks in task ‘b’.

For task ‘a’ the output is:

the argu ment

For task ‘b’ it is:

the “argu” ment

I’d have expected that ‘a’ already gives the desired outcome.

I can’t reproduce this with Gradle 1.6.

Here’s what I tried:

apply plugin: "application"
apply plugin: "groovy"
  mainClassName = "Main"
  repositories {
 mavenCentral()
}
  dependencies {
 groovy localGroovy()
}
  run {
 args = [ "the \"argu\" ment" ]
}

Then run: ‘gradle run’.

The arg is quoted.

I still see this with gradle 1.6 with the ‘run’ task as well as with my example of ‘JavaExec’.

% gradle run

:compileJava UP-TO-DATE

:compileGroovy UP-TO-DATE

:processResources UP-TO-DATE

:classes UP-TO-DATE

:run

the argu ment

BUILD SUCCESSFUL

Here my gradle info:


Gradle 1.6


Gradle build time: Dienstag, 7. Mai 2013 09:12 Uhr UTC

Groovy: 1.8.6

Ant: Apache Ant™ version 1.8.4 compiled on May 22 2012

Ivy: 2.2.0

JVM: 1.7.0_04 (Oracle Corporation 23.0-b21)

OS: Windows 7 6.1 amd64

Ah, Windows… the great destroyer of quotes. I’ll dig a little deeper. There are some long standing JDK (ProcessBuilder and friends) bugs in this area that I think are biting here.

Sorry. I should have made this more explicit. I wrote it in the heading, though. :expressionless:

Yeah, my fault for not picking it up the first time.

Raised as GRADLE-2779.