Adding code to configuration phase of custom task

Hi there,

I’ve got a custom task that extends test, and I want to switch off the junit xml output as this task runs cucumber tests. When it’s in my gradle build file like this, it’s fine:

task cucumberTests(type: Test, dependsOn: [ "testClasses" ],
 ) {
  systemProperties = System.getProperties()
 include "**/RunCompletedTestsCuke.class"
 reports.junitXml.enabled = false
 reports.html.enabled = false
}

What I’d like to do is create a custom task class that I can then use for running different sets of cucumber tests. So far I have this:

class CucumberTestTask extends Test {
    String runnerGlob
    @TaskAction
 void setupConfig(){
      //propagate command line props to tests
   systemProperties = System.getProperties()
      //only include the specified runner
  include runnerGlob
      //switch off the default junit reports as they fail with long cucumber test names
  reports.junitXml.enabled = false
  reports.html.enabled = false
 }
}

But because the disabling of the reports happens in the task action, not in the configuration phase like it doesn in the build.gradle, the setting doesn’t get picked up. My question is how do I add logic to the configuration phase of a custom task, rather than in the task action?

Thanks.

A common practice here is to do it in your task constructor.

That’s great - fixes my problem! Thanks!