I am writing tasks in Gradle to work with my Docker containers. One of them is going to kill and remove 2 containers. Usual command in Linux looks like
docker-compose -f docker-compose.yml kill postgresql redis wap-pattern && docker-compose -f docker-compose.yml rm -f wap-pattern postgresql redis
And it works fine, but in Kotlin I have to use list of arguments, so in my code it looks like
tasks.register<Exec>("downAll") {
group = "docker"
commandLine = listOf("docker-compose", "-f", "docker-compose.yml", "kill", "postgresql", "redis", "&&", "docker-compose", "-f", "docker-compose.yml", "rm", "-f", "postgresql", "redis")
}
And unfortunately it doesn't work at all, exiting with error code. Apparently Kotlin doesn't parse && correctly.
So, how can I handle this problem and make my task work? Can I somehow avoid ampersand and call command line execution 2 times in the same task body?