Fail local gradle build if sonar errors exist

I have a gradle project and sonarqube plugin in my gradle project. I am currently using jacoco to fail build if the code coverage is below some value. All this is happening in local ie, I do a "gradle clean build" and build fails if the code coverage is less than say 80% or if a test case fails.

I want my build to fail if I have a critical issue (sonar error) in my code or if there is a sonar code smell. This is to enforce code quality before the developer even decides to commit his code to git. We have a jenkins server and sonar server running remotely and integration is working fine.

So far I have hear about code breaker plugin, which I have still not figured out.

Is there a gradle/groovy script that can either fetch quality gate condition from remote or is there a way to create those conditions locally (not by running sonarqube locally) say in a properties file or some groovy script. So when my sonar analysis is complete the task will pick the sonar analysis report and fetch metrics from the report and fail the local-gradle-build if the criteria/condition match.

For ex. my new code changes have a critical issue reported by sonar so break the build.

Is it possible to create quality gates or rules for local say in a text file?

Does anyone have any idea?

All I want to do here is run my gradle build like usual but it would fail if there are any sonar issues in my code.