Need to block Android run on failed gradle task

228 views Asked by At

I have an android project in Android studio that I would like to use detekt as a static code analyzer. 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.

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.

1

There are 1 answers

0
DamosCas On

Turns out the solution was to add the gradle task in all the files. In my case I needed to add a top level gradle file for detekt. 'detekt.gradle'

Then in the main gradle file I have

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

Then in each module gradle file I put:

preBuild.dependsOn(detekt)

This makes every build of the modules run detekt first and if detekt fails the build will not complete.