Gradle can't find programs through its exec-Task (PATH?)

Hey there!

I’ve got a fairly simple (I hope) question for you guys.
Small summary, I’ve got a multiproject build but its structure isn’t of importance. (other than it’s just a flat Project Structure with an “empty” project on top, so i can inject dependencies)

I created two tasks:

subprojects {
apply plugin: 'java'

tasks.create(name: 'prepDocker', type: Copy, dependsOn: build) {
    from "build/libs/"
    from 'Dockerfile'
    into "build/docker/"

tasks.create(name: 'buildDocker', type: Exec, dependsOn: prepDocker) {
    doFirst {
        //needs to be done here, otherwise it can't get the version number since it gets set in the projects configuation-phase
        commandLine 'docker', 'build', '--force-rm', '-t', "${}/${}:${project.version}", '.'
    workingDir '/build/docker'

which seemed to work fine in the beginning.

But starting from about 2-3 weeks ago I started getting errors that gradle isn’t able to find the executable. (also tried a testtask with echo, didn’t find that either)

Has something changed? please tell me there’s something obvious I’m missing.



Also had a similar issue. Also with docker and others can’t replicate it despite using same environment settings.

I ended up having to do a workaround in my Task class (which works for me, but not sure if it will cause others problems):

ByteArrayOutputStream whichCommandOutputStream = new ByteArrayOutputStream()
        project.exec {
            commandLine 'which', 'docker'
            standardOutput = whichCommandOutputStream
            workingDir project.rootDir

        String dockerPath = whichCommandOutputStream.toString().trim()"Docker is located at ", dockerPath)

        ByteArrayOutputStream commandOutput = new ByteArrayOutputStream()

        def proc = project.exec {
            commandLine dockerPath, 'run'
            standardOutput = commandOutput
            workingDir project.rootDir

Is there a better solution to this? Or why this is happening to some people and not to others.
Also worth mentioning that my $PATH contains the docker path already.