Gradle Exec task for docker adds extra quotes to command line

Viewed 93

I have a gradle exec task where I want to run docker container.

tasks.register<DefaultTask>("apiLinter") {
    var outcome=project.execWithOutput {
        commandLine("docker run --rm -it -v  ${projectDir}/src/main/resources/static:/tmp stoplight/spectral lint /tmp/openapi.yaml --ruleset=/tmp/spectral.json")
    }
    println("outcome $outcome")
    outputs.upToDateWhen { false }
}


fun Project.execWithOutput(spec: ExecSpec.() -> Unit) = ByteArrayOutputStream().use { outputStream ->
    exec {
        this.executable = "sh"
        this.spec()
        this.standardOutput = outputStream
    }
    outputStream.toString().trim()
}

The issue seems with:

 commandLine("docker run --rm -it -v  ${projectDir}/src/main/resources/static:/tmp stoplight/spectral lint /tmp/openapi.yaml --ruleset=/tmp/spectral.json")

It looks like when the command is executed there is an extra quote automatically added to the command.

Output:

FAILURE: Build failed with an exception.

* What went wrong:
A problem occurred configuring project ':catalog-api'.
> Could not create task ':catalog-api:apiLinter'.
   > A problem occurred starting process 'command 'docker run --rm -it -v  /Users/gianni/Develeopment/catalog-aggregator/catalog-api/src/main/resources/static:/tmp stoplight/spectral lint /tmp/openapi.yaml --ruleset=/tmp/spectral.json''

Thanks for the help

1 Answers

No, Gradle doesn't add extra quotes to the command line. What you see in Gradle's output is a try to (generically) make the output more friendly to read.

'command 'docker run  ...''
^        ^               ^^

Add --stacktrace and --info to the Gradle execution (gradlew --info --stacktrace) to help identifying the root cause of the issue.

Related