How to skip sonarRunner task if nothing changes?


(Gaurav Singh) #1

I want to skip sonarRunner if no code change happened.

gradlew clean build artifactoryPublish sonarRunner

Below does not work

sonarRunner {
  onlyIf { javaCompile.didWork }
}

(Peter Niederwieser) #2

It’s not quite as straightforward. Try something like:

tasks.sonarRunner {
    onlyIf { projects.any { tasks.withType(JavaCompile).any { it.didWork } } }
}

(Gaurav Singh) #3

Hi Peter,

We tried to skip sonarRunner with below configuration, but behavior is not very consistent.

tasks.sonarRunner {
  println project.name + "----" + tasks.withType(JavaCompile).any { it.didWork }
 onlyIf {
tasks.withType(JavaCompile).any { it.didWork } }
}

It works if we run

%> gradle sonarRunner But if we run and tasks.withType(JavaCompile).any { it.didWork } evaluates to false %. gradle build sonarRunner

it doesn’t skip

Let me know where we would be wrong


(Peter Niederwieser) #4

You have to do the ‘println’ inside ‘onlyIf’. Otherwise, it will always print ‘false’, because none of the tasks has run yet.