Finalizer task does not run if finalized task fails

I’ve encountered a problem setting up a finalizer task for an integrationTest task. The code can be found at https://github.com/aalmiray/griffon2 , specifically https://github.com/aalmiray/griffon2/blob/master/gradle/integration-test.gradle

These are the interesting bits

task integrationTest(type: Test, dependsOn: jar) {
    testClassesDir = sourceSets.integrationTest.output.classesDir
    classpath = sourceSets.integrationTest.runtimeClasspath
    reports.html.enabled = false
}
  task integrationTestReport(type: TestReport, dependsOn: integrationTest) {
    destinationDir = file("${buildDir}/reports/integration-tests")
    reportOn integrationTest
}
  integrationTest.mustRunAfter test
integrationTest.finalizedBy integrationTestReport

The ‘integrationTest’ task disables html reporting so that ‘integrationTestReport’ can specify a different location as I want to keep regular tests separated from integration tests. So far running ‘gradle clean integrationTest --dry-run’ results in

:sample-swing-groovy:compileJava SKIPPED
:sample-swing-groovy:compileGroovy SKIPPED
:sample-swing-groovy:processResources SKIPPED
:sample-swing-groovy:classes SKIPPED
:sample-swing-groovy:instrument SKIPPED
:sample-swing-groovy:copyCoberturaDatafile SKIPPED
:sample-swing-groovy:compileIntegrationTestJava SKIPPED
:sample-swing-groovy:compileIntegrationTestGroovy SKIPPED
:sample-swing-groovy:processIntegrationTestResources SKIPPED
:sample-swing-groovy:integrationTestClasses SKIPPED
:sample-swing-groovy:jar SKIPPED
:sample-swing-groovy:integrationTest SKIPPED
:buildDashboard SKIPPED
:sample-swing-groovy:integrationTestReport SKIPPED
:sample-swing-groovy:generateCoberturaReport SKIPPED
:sample-swing-groovy:performCoverageCheck SKIPPED

which means the ‘finalizedBy’ setting works. Running the test for real (while it’s green) results in

:sample-swing-groovy:compileJava UP-TO-DATE
:sample-swing-groovy:compileGroovy
:sample-swing-groovy:processResources
:sample-swing-groovy:classes
:sample-swing-groovy:instrument SKIPPED
:sample-swing-groovy:copyCoberturaDatafile SKIPPED
:sample-swing-groovy:compileIntegrationTestJava UP-TO-DATE
:sample-swing-groovy:compileIntegrationTestGroovy
:sample-swing-groovy:processIntegrationTestResources UP-TO-DATE
:sample-swing-groovy:integrationTestClasses
:sample-swing-groovy:jar
:sample-swing-groovy:integrationTest
:buildDashboard UP-TO-DATE
:sample-swing-groovy:integrationTestReport
:sample-swing-groovy:generateCoberturaReport SKIPPED
:sample-swing-groovy:performCoverageCheck SKIPPED

We’re 2 for 2. The problem appears if the ‘integrationTest’ task fails because of a test failure

:sample-swing-groovy:compileJava UP-TO-DATE
:sample-swing-groovy:compileGroovy
:sample-swing-groovy:processResources
:sample-swing-groovy:classes
:sample-swing-groovy:instrument SKIPPED
:sample-swing-groovy:copyCoberturaDatafile SKIPPED
:sample-swing-groovy:compileIntegrationTestJava UP-TO-DATE
:sample-swing-groovy:compileIntegrationTestGroovy
:sample-swing-groovy:processIntegrationTestResources UP-TO-DATE
:sample-swing-groovy:integrationTestClasses
:sample-swing-groovy:jar
:sample-swing-groovy:integrationTest
  sample.swing.groovy.SampleTest > doNotTypeNameAndClickButton FAILED
    java.lang.AssertionError at SampleTest.groovy:57
  2 tests completed, 1 failed
:sample-swing-groovy:integrationTest FAILED
:buildDashboard UP-TO-DATE
:sample-swing-groovy:generateCoberturaReport SKIPPED
:sample-swing-groovy:performCoverageCheck SKIPPED
  FAILURE: Build failed with an exception.
  * What went wrong:
Execution failed for task ':sample-swing-groovy:integrationTest'.
> There were failing tests. See the results at: file:///Users/aalmiray/dev/github/griffon2/samples/sample-swing-groovy/build/test-results/

You can appreciate that ‘integrationTestReport’ was not executed. Funny thing is that buildDashboard and cobertura tasks were indeed added to the task DAG. The cobertura plugin 2.0.3 uses task finalizers btw.

So my question is: where did I go wrong? Is there something missing in this configuration or did I hit a corner case for finalizer tasks?

TIA Andres

1 Like

Hi Andres,

At the moment Gradle does not support A.finalizedBy(B) together with B.dependsOn(A) and you will get the behaviour you observed.

Can you tell me more about why you want to do that?

cheers Perryn

Right. Marcin told me that having both settings would cause trouble, so I removed dependsOn from ‘integrationTestReport’ however the problem persists.

Originally I wrote the tasks so that ‘integrationTestReport’ would depend on ‘integrationTest’. Next I saw that the report was not generated if the tests failed, so I added the finalizedBy without removing dependsOn as I didn’t think leaving it would cause problems.

ah, because you did this

reportOn integrationTest

the ‘integrationTestReport’ task automatically ‘dependsOn integrationTest’ as documented here

FWIW I think your use case is reasonable. I will see if we can support it better. In the meantime try this instead:

reportOn integrationTest.binResultsDir
1 Like

Thanks, the workaround is giving me the expected result.