Java Gradle 找不到根项目参数的方法“()”

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/37100254/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-11 19:00:14  来源:igfitidea点击:

Gradle Could not find method “() for arguments on root project

javagradlebuild.gradle

提问by Spotlight

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

我有一个 Gradle 项目,我正在尝试修复它,并且正在慢慢学习 Gradle 的语法。

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.

目前我有一个库,如果IS_RELEASE(环境变量)被设置,那么它会将它上传到我们的生产服务器。如果没有,它会将其复制到我们的测试位置。

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 buildI get the following:

代码看起来很好,不会在 NetBeans 中导致任何语法错误。但是,当我运行时,gradle build我得到以下信息:

: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

: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:构建失败,出现异常。

  • 其中:
    构建文件 '/path/to/gradle/project/build.gradle' 行:62

  • 出了什么问题:
    任务“:检测”执行失败。在根项目“myproject”上找不到参数 [build_934uxjujs447ej84orspcupbq$_run_closure4$_closure15@3a230b5f] 的方法“()”。

  • 尝试:
    使用 --stacktrace 选项运行以获取堆栈跟踪。使用 --info 或 --debug 选项运行以获得更多日志输出。

    构建失败

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

第 62 行是apply from: “{$rootDir}/copy-testing.gradle”

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

我在这里错过了什么吗?我从这里采取了一些类似的想法并修复了解决方案。(请参阅“从文件应用”标题。)

采纳答案by Manfred Radlwimmer

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.

你的引号是错误的。在您的代码中,您使用(从链接网站复制)(双曲线引号)而不是常规(灵巧)“s。