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'
}
}
}
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: ...
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With