如何自动接受Gradle ToS来进行build --scan并仍然设法运行不扫描的build?

时间:2018-10-03 22:39:59

标签: gradle build-error

  

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

像这样:

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

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

> Could not find method buildScan() for arguments…
     

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

     

有人可以告诉我我在做什么错吗?

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

3 个答案:

答案 0 :(得分:7)

只需测试buildScan

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

答案 1 :(得分:0)

这可能不是一个好的解决方案,但这是一种解决方法:使用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
}

答案 2 :(得分:0)

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

在 Jenkins 中,您将看到构建扫描结果的链接。 enter image description here