【问题标题】:How to accept Gradle ToS for `build --scan` automatically and still manage to run build without a scan?如何自动接受“build --scan”的Gradle ToS并且仍然设法在没有扫描的情况下运行构建?
【发布时间】:2018-10-03 22:39:58
【问题描述】:

我正在使用 Gradle 4.6,它允许我使用 build scans 运行 --scan 选项无需显式应用或下载 额外的插件很棒。然而,这迫使我添加 buildScan 在我的 build.gradle 文件中接受服务条款。

像这样:

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

当我随后在没有 --scan 选项的情况下运行 gradle build 时,我 得到以下错误信息:

> Could not find method buildScan() for arguments…

我不想每次都修改 build.gradle 文件 想要/不想要扫描。我不想明确应用插件 (防火墙问题),我没有机会接受条款 我也看到记录在命令行上的服务。

谁能告诉我我做错了什么?

此问题的格式类似于引用,因为它已在 Gradle Forums 上提出。但它没有答案。我正在使用 Gradle 4.10.2,但问题仍然存在。我决定在这里提请更多注意这个问题。

【问题讨论】:

    标签: gradle build-error


    【解决方案1】:

    只测试buildScan是否存在

    if (hasProperty('buildScan')) {
        buildScan {
            termsOfServiceUrl = 'https://gradle.com/terms-of-service'
            termsOfServiceAgree = 'yes'
        }
    }
    

    【讨论】:

    • 如果有人知道如何将其翻译成 Kotlin DSL,请在 stackoverflow.com/q/55725574/1127485 回复,在此先感谢。
    • 这应该放在 build.gradle (app) 中的哪个部分?
    • @TaslimOseni 将它放在顶层 build.gradle 中(不是具有依赖项的那个)。把它放在buildscript上方
    【解决方案2】:

    你只需要在 buid.gradle(Project) 文件中添加上面的代码块 并且构建扫描将自动发布。

    在 Jenkins 中,您将链接到构建扫描的结果。

    【讨论】:

    【解决方案3】:

    这可能不是一个好的或适当的解决方案,但这里有一个解决方法:使用 try/catch 来吞下错误,例如:

    try {
        buildScan {
            termsOfServiceUrl = 'https://gradle.com/terms-of-service'
            termsOfServiceAgree = 'yes'
        }
    } catch (MissingMethodException e){
       // This isn't the exception you're looking for
    }
    

    【讨论】:

      猜你喜欢
      • 2021-12-19
      • 2015-09-08
      • 1970-01-01
      • 2021-02-08
      • 1970-01-01
      • 2019-07-31
      • 2022-10-02
      • 2014-12-09
      • 2015-11-30
      相关资源
      最近更新 更多