Matthew Cline
Matthew Cline

Reputation: 2376

How to use commandLine() within buildFinished

In $HOME/.gradle/init.gradle I have:

gradle.buildFinished { buildResult ->
    commandLine 'bash', "blah blah blah"
}

Doing gradle build the build succeeds, but after it succeeds I get the error:

Could not find method commandLine() for arguments [bash, blah blah blah] on build 'FooBar' of type org.gradle.invocation.DefaultGradle.

The answer to the question Could not find method commandLine() doesn't help as either putting (type: Exec) after gradle.buildFinished or wrapping the whole thing in exec { } causes Gradle to fail right from the start rather than the build succeeding and then my post-build hook failing.

I'm using Gradle version 6.3

Upvotes: 1

Views: 560

Answers (1)

Opal
Opal

Reputation: 84756

You've misconfigured commandLine. With the following build.gradle:

task lol {
    doLast {
        println "lol"
    }
}

and ~/.gradle/init.gradle:

gradle.buildFinished { buildResult ->
    exec { 
        commandLine 'bash', '-c', 'echo lol2'
    }
}

it works as expected.

Upvotes: 2

Related Questions