'In gradle.build file, is there a way to access what the user has passed in as --tests?

For example, if the user runs gradle clean test --tests some.package.SomeTest is there a way that I could do System.out.println("User passed " + task.commandToGetWhatUserPassedAsTests()) in the gradle.build file and see in the output User passed some.package.SomeTest



Solution 1:[1]

I answered my own question.

tasks.withType(Test) {
  for(TaskExecutionRequest taskExecutionRequest : project.gradle.startParameter.taskRequests) {
    for(Iterator<String> iterator = taskExecutionRequest.args.iterator(); iterator.hasNext();) {
      if(iterator.next().equals("--tests")) {
        System.out.println("--tests" + iterator.next())
      }
    }
  }
}

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 jlt250