Build Scan不适用于Android中的Gradle

时间:2017-06-27 19:38:12

标签: android android-gradle

我正在关注https://guides.gradle.org/building-android-apps/上的Gradle教程。所以这部分的最后一部分是运行构建扫描。我的做法与我要求的完全相同。但是Android Studio继续说“错误:(14,0)无法为org.gradle.api.Project类型的根项目'HelloWorldGradle'获取未知属性'com'。”

这是我的顶级构建文件(build.gradle(Project:HelloWorldGradle)):

// Top-level build file where you can add configuration options common to all        sub-projects/modules.

buildscript {
    repositories {
        jcenter()
        maven { url 'https://plugins.gradle.org/m2' }
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:2.4.0-alpha7'
        classpath 'com.gradle:build-scan-plugin:1.7.1'
    }
}  

apply plugin: com.gradle.build-scan

buildScan {
    licenseAgreementUrl = 'https://gradle.com/terms-of-service'
    licenseAgree = 'yes'
}

allprojects {
    repositories {
        jcenter()
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

5 个答案:

答案 0 :(得分:4)

在build.gradle项目的顶级文件中写入以下内容后,我的问题得到解决

plugins {
    id 'com.gradle.build-scan' version '1.16'
}

buildScan {
    licenseAgreementUrl = 'https://gradle.com/terms-of-service'
    licenseAgree = 'yes'
    publishAlways()
}

答案 1 :(得分:1)

问题在于build.gradle

中的以下行
  

apply plugin:com.gradle.build-scan

您需要更新为

apply plugin: 'com.gradle.build-scan'

您需要注意的另一件事是始终将com.gradle.build-scan插件作为第一个插件,如下所示:

apply plugin: 'com.gradle.build-scan'
apply plugin: 'java'

否则,您会看到:

  

警告:构建扫描插件是在其他插件之后应用的。该   构建扫描插件时捕获的数据更全面   先申请。

     

请参阅Create Server Error了解具体方法   解决这个问题。

让我知道这是否有效。

答案 2 :(得分:1)

于2019年2月编辑:

在下面使用2.1版本而不是1.15.1


当前(2018年7月)进行构建扫描的方法是将以下内容添加到应用gradle文件中

plugins {
id 'com.gradle.build-scan' version '1.15.1'                     
}

buildScan {
    termsOfServiceUrl = 'https://gradle.com/terms-of-service'     
    termsOfServiceAgree = 'yes'                                   

    publishAlways()                                               
}

,将来最好再次从gradle build scan user manual获取它,以便再次更改它。

答案 3 :(得分:1)

根据gradle doc,这应该是最新的实现方式

    plugins {
            id 'com.gradle.build-scan' version '2.3'   
    }

    buildScan {
            termsOfServiceUrl = 'https://gradle.com/terms-of-service'     
            termsOfServiceAgree = 'yes'                                   

            publishAlways()                                                
    }

答案 4 :(得分:0)

从终端运行下一个命令./gradlew build --scangradlew build --scan

此外,请在命令行中同意服务条款。