Creating a Gradle plugin with a dependency on another (external) plugin?

I want to create a plugin that automatically applies other (external plugins). This requires setting the buildscript dependency for the plugin before I call “apply plugin”. However it seems like I can’t add buildscript dependencies in a plugin or I get: You can’t change a configuration which is not in unresolved state!

Is there a solution to this ?

My sample (non-working) code:

import org.gradle.api.Project
import org.gradle.api.Plugin
class SamplePlugin implements Plugin<Project>{
  void apply(Project project) {
      project.buildscript.dependencies.add("classpath","net.sourceforge.cobertura:cobertura:1.9.4.1");
      project.configure(project){
               apply plugin: 'cobertura'
     }
  }
}
1 Like

I’ve already answered here: http://stackoverflow.com/questions/10081299/creating-a-gradle-plugin-with-a-dependency-on-another-external-plugin