Why can't I add dependencies created with the DependencyHandler to a configuration?

This setup works for me.

ext.scripts = [
        idea: dependencies.create(group: 'ca.jptech.gradle.scripts', name: 'idea', version: '1', ext: 'gradle'),
        javafx7: dependencies.create(group: 'ca.jptech.gradle.scripts', name: 'javafx7',version: '1', ext: 'gradle')
]
  allprojects {
    //...snip...
      configurations {
        gradleScripts
    }
      dependencies {
        gradleScripts scripts.idea
        gradleScripts scripts.javafx7
    }
      apply from: configurations.gradleScripts.fileCollection(scripts.idea).singleFile
}

However, this setup fails.

ext.scripts = [
        idea: dependencies.create(group: 'ca.jptech.gradle.scripts', name: 'idea', version: '1', ext: 'gradle'),
        javafx7: dependencies.create(group: 'ca.jptech.gradle.scripts', name: 'javafx7',version: '1', ext: 'gradle')
]
  allprojects {
    //...snip...
      configurations {
        gradleScripts
    }
      // The following line causes the build to fail
    scripts.each { dependencies.gradleScripts it }
      apply from: configurations.gradleScripts.fileCollection(scripts.idea).singleFile
}

The commented line causes my build to fail with the error:

Cannot convert the provided notation to an object of type Dependency: idea=DefaultExternalModuleDependency{group='ca.jptech.gradle.scripts', name='idea', version='1', configuration='default'}.

I can’t figure out why. I must be misunderstanding something because I thought both setups would do the exact same thing.

Of course I figured this out a few minutes after I posted. I’m still getting the hang of closures and that’s what tripped me up. My array has a map of dependencies, so the closure for the scripts.each line can’t use the implicit ‘it’ argument. It needs to define the arguments and use the values from the map. The script line needed to be changed to this:

scripts.each { key, dependency -> dependencies.gradleScripts dependency }