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