【问题标题】:Gradle DSL method not found : testCompile()未找到 Gradle DSL 方法:testCompile()
【发布时间】:2017-07-07 08:45:51
【问题描述】:

我正在使用 gradle 版本 - 3.3-all 和 gradle 插件 - gradle:2.3.3 我想写测试用例。所以根据这个page,我在应用程序的顶部build.gradle 文件中包含了以下内容。

        testCompile 'junit:junit:4.12'
        testCompile 'org.mockito:mockito-core:1.10.19'

但我收到错误提示

Error:(11, 0) Gradle DSL method not found: 'testCompile()'
Possible causes:<ul><li>The project 'TopLevelProject' may be using a version of the Android Gradle plug-in that does not contain the method (e.g. 'testCompile' was added in 1.1.0).

可能是什么问题?

【问题讨论】:

    标签: android gradle android-gradle-plugin mockito android-testing


    【解决方案1】:

    添加Java plugin

    apply plugin: 'java'
    

    【讨论】:

      【解决方案2】:

      在 gradle 中配置:compileruntimetestCompile 等来自java 插件

      但在android中我认为你需要apply plugin: 'com.android.application'

      编辑:请分享您的根build.gradle 和应用程序build.gradle,尤其是android 闭包、依赖项和插件,并描述其中的位置。

      有时是结构性问题,与应用相关的内容位于根目录build.gradle

      【讨论】:

        【解决方案3】:

        我没有评论的声誉,所以我发布这个作为答案。

        我遇到了类似的问题,尝试在应用的构建文件中应用 Java 插件和 testCompiles,即:project/app/build.gradle,而不是项目的构建文件。 p>

        apply plugin: 'com.android.application'
        
        dependencies {
           ...
           testCompile 'junit:junit:4.12'
           testCompile 'org.mockito:mockito-core:1.10.19'
        }
        

        【讨论】:

          猜你喜欢
          • 2017-10-27
          • 1970-01-01
          • 2019-09-29
          • 2015-09-25
          • 2015-05-19
          • 2017-04-19
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多