Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

gradle

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' 
    }
  }
}
like image 308
vicsz Avatar asked Apr 09 '12 23:04

vicsz


1 Answers

The way to go about this is to publish a pom.xml or ivy.xml along with the plugin Jar that describes the plugin's dependencies. Alternatively, you can write a script plugin that declares its dependencies in a buildscript {} section. A script plugin is simply a reusable build script that gets applied with apply from: ....

like image 57
Peter Niederwieser Avatar answered Sep 22 '22 16:09

Peter Niederwieser