简体   繁体   English

需要阻止 Android 在失败的 gradle 任务上运行

[英]Need to block Android run on failed gradle task

I have an android project in Android studio that I would like to use detekt as a static code analyzer.我在 Android 工作室有一个 android 项目,我想将 detekt 用作 static 代码分析器。 I can run detekt through a gradle task and I am able to queue it up before the run of the app by using the Android run configurations, but I cannot seem to get it to stop the run if the task returns an error code.我可以通过 gradle 任务运行 detekt,并且可以使用 Android 运行配置在应用程序运行之前将其排队,但如果任务返回错误代码,我似乎无法让它停止运行。

I have detekt running from the command line in my build pipeline, but I would like the developer to also fail their run on their development machine.我在我的构建管道中检测到从命令行运行,但我希望开发人员也无法在他们的开发机器上运行。

Turns out the solution was to add the gradle task in all the files.原来解决方案是在所有文件中添加 gradle 任务。 In my case I needed to add a top level gradle file for detekt.在我的例子中,我需要为 detekt 添加一个顶级 gradle 文件。 'detekt.gradle' '检测.gradle'

Then in the main gradle file I have然后在主要的 gradle 文件中我有

allprojects {
    repositories {
        google()
        jcenter()
    }
    apply from: "$rootDir/detekt.gradle"
}

Then in each module gradle file I put:然后在每个模块 gradle 文件中放入:

preBuild.dependsOn(detekt)

This makes every build of the modules run detekt first and if detekt fails the build will not complete.这使得模块的每个构建都首先运行 detekt,如果 detekt 失败,则构建将无法完成。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM