Running the --scan option with Gradle 4.6 without changing my build.gradle

I am using Gradle 4.6 which allows me to run build scans using the --scan option without having to explicitly apply or download extra plugins which is great. However this forces me to add the buildScan Terms of Service acceptance in my build.gradle file. When I subsequently run my build without the --scan option I get the following error message

Could not find method buildScan() for arguments…

I don’t want to have to modify the build.gradle file every time I want/dont want a scan. I don’t want to apply the plugin explicitly (firewall issues) and I don’t get the chance to accept the of Terms of Service on the command line which I have also seen documented.

Can anyone tell me what I am doing wrong?


I am experiencing the same issue when I run
./gradlew build --scan
under the cygwin. It does not allow me to answer yes/no to the license terms, versus when I run this under “command prompt” it lets me to answer “yes/no” on interactive prompt.
The output of command when I run it under cygwin (windows):

fa@fa-laptop-win iCoup$ ./gradlew build --scan

Task :assemble UP-TO-DATE
Task :check UP-TO-DATE
Task :build UP-TO-DATE


The build scan was not published due to a configuration problem.

The Gradle Terms of Service have not been agreed to.

To agree to the Gradle Terms of Service, include the following in your root project’s configuration:
buildScan { termsOfServiceUrl = “”; termsOfServiceAgree = “yes” }

For more information, please see

Alternatively, if you are using Gradle Enterprise, specify the server location.
For more information, please see


And if I add
buildScan { termsOfServiceUrl = “”; termsOfServiceAgree = “yes” }
to my build.gradle - then command executes fine, but with this line in build.gradle I can not execute any other commands in my build under pure windows command prompt nor under cygwin. It tells me:

fa@fa-laptop-win iCoup$ ./gradlew properties

FAILURE: Build failed with an exception.

  • Where:
    Build file ‘C:\dev\iCoup\build.gradle’ line: 22

  • What went wrong:
    A problem occurred evaluating root project ‘iCoup’.

Could not find method buildScan() for arguments [build_6ukaol4evri9488qeq6b2hdy3$_run_closure3@49eac987] on root project ‘iCoup’ of type org.gradle.api.Project.

  • Try:
    Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

  • Get more help at


This question is answered on Stack Overflow. For your convenience, I’m re-posting the answer here:

test the existence of buildScan

if (hasProperty('buildScan')) {
    buildScan {
        termsOfServiceUrl = ''
        termsOfServiceAgree = 'yes'