I have a Gradle build which produces the main deliverable artifact (an installer) of my product. The Gradle project which models this has a number of different dependencies in different configurations. Many of those dependencies are on the default configuration of external modules, and some of those modules have a testResults configuration that contains the (zipped) results of the test task.

It's important that those test results for all dependencies, where they exist, be published as artifacts of the main product build (to use as evidence that testing took place and was successful). It's not an issue if they don't exist.

I tried to do this by iterating over all configurations of the product build, iterating over the dependencies in each and adding a programmatically created dependency (in a new configuration created for this purpose) on the testResults configuration of the module.

In other words, I create dependencies like this:

def processDependencyForTests( Dependency dependency ) {

    def testResultsDependency = [
      'group' : dependency.group,
      'name' : dependency.name,
      'version' : dependency.version,
      'configuration' : 'testResults'
      ]

    project.dependencies.add 'allTestResults', testResultsDependency

This populates that configuration just fine, but of course when I try to do anything with it, it fails the first time I encounter a dependency on a module that doesn't actually have a testResults configuration:

   def resolvedConfiguration = configurations.allTestResults.resolvedConfiguration

Results in this:

Build file 'C:\myproduct\build.gradle' line: 353

* What went wrong:
Execution failed for task ':myproduct:createBuildRecord'.
> Could not resolve all dependencies for configuration ':myproduct:allTestResults'.
   > Module version group:mygroup, module:myprodu
Edit
Report