Gradle Could not find method “() for arguments on

2020-08-25 04:17发布

I have a Gradle project that I'm attempting to fix and am slowly learning Gradle's syntax as I go.

Currently I have a library that if IS_RELEASE (an environmental variable) is set, then it uploads it to our production servers. If not, it copies it to our testing location.

The code is as follows:

task(detect) << {
    if(System.getenv().containsKey("IS_RELEASE"))
        apply from: “{$rootDir}/upload-pack.gradle”
    else
        apply from: “{$rootDir}/copy-testing.gradle”
}

detect.mustRunAfter build
build.finalizedBy detect

The code looks just fine and doesn't cause any syntax errors in NetBeans. However, when I run gradle build I get the following:

:compileJava UP-TO-DATE
:processResources UP-TO-DATE
:classes UP-TO-DATE
:jar UP-TO-DATE
:assemble UP-TO-DATE
:compileTestJava UP-TO-DATE
:processTestResources UP-TO-DATE
:testClasses UP-TO-DATE
:test UP-TO-DATE
:check UP-TO-DATE
:build UP-TO-DATE
:detect FAILED

FAILURE: Build failed with an exception.

  • Where:
    Build file '/path/to/gradle/project/build.gradle' line: 62

  • What went wrong:
    Execution failed for task ':detect'. Could not find method “() for arguments [build_934uxjujs447ej84orspcupbq$_run_closure4$_closure15@3a230b5f] on root project 'myproject'.

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

    BUILD FAILED

Line 62 is apply from: “{$rootDir}/copy-testing.gradle”.

Am I missing something here? I have taken some similar ideas from here and fixed the solutions up. (See the "Apply From a File" header.)

1条回答
仙女界的扛把子
2楼-- · 2020-08-25 04:24

Your quotation marks are wrong. In your code you are using (copied from the linked website) and (Double curved quotes) instead of regular (ambidextrous) "s.

查看更多
登录 后发表回答