Can not find custom method in build.gradle with MissingMethodException
<p>I got an error when I tried to call a custom method in <code>build.gradle</code>.</p>

<p>In <code>build.gradle</code> file:</p>

<pre><code>def func() {
    String str = "hello world!"
    str
}

buildscript {
    repositories {
        mavenCentral()
    }

    dependencies {
        String str = func()
        println "$str"

        ...... // Other code
    }
}
</code></pre>

<p>The error I got is as followed:</p>

<pre><code>Caused by: org.gradle.api.internal.MissingMethodException: Could not find method func() for arguments [] on org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler_Decorated@1c86d7b4.
</code></pre>