Show test reports when test coverage verification fails

My Gradle build does the following

  1. Runs the tests
  2. Opens a test report in the browser
  3. Opens a test coverage in the browser
  4. Verifies that test coverage is at least 80%

The relevant tasks in build.gradle are:

task testWithReports {   
  dependsOn 'clean'
  dependsOn 'test'
  dependsOn 'jacocoTestReport'
  dependsOn 'showCoverage'
  dependsOn 'showTestResults'
  dependsOn 'jacocoTestCoverageVerification'
}

jacocoTestReport {
  reports {
    xml.enabled false
    csv.enabled false
    html.destination file("${buildDir}/jacocoHtml")
  }
}

task showCoverage {
  doLast {
    desktop.browse "file:///${buildDir}/jacocoHtml/index.html".toURI()
  }
}

task showTestResults {
  doLast {
    desktop.browse "file:///${buildDir}/junitHtml/index.html".toURI()
  }
}

jacocoTestCoverageVerification {
  violationRules {
    rule {
      limit {
        minimum = 0.8
      }
    }
  }
}

If I run testWithReports and the jacocoTestCoverageVerification subtask fails, the test reports are not opened. Is there a way to define these tasks which ensures that these reports are always opened?