1
votes

When writing a gradle plugin, is it possible to add dependencies to the compile and testCompile classpath for projects that apply the plugin?

If so, is there a simple example that you can reference?

As an example; let's say I wanted to write a plugin that, among other things, added the AWS Java API jars to a project i.e. I get the the jars on the classpath of the project where I apply the plugin allowing me to compile against them.

Thanks

1

1 Answers

0
votes

I am not fully sure I understand the question but you can look at the gradle war plugin (https://github.com/gradle/gradle/blob/master/subprojects/plugins/src/main/groovy/org/gradle/api/plugins/WarPlugin.java) which defines new tasks providedCompile which extends compile

Edit : making plugin with its dependencies

In your example, its totally possible that the plugin defines its own dependencies like in a normal build.gradle file

repositories {
  mavenCentral()
}
dependencies {
  compile "com.amazonaws:aws-java-sdk-ec2:1.10.2"
}

see for example the was plugin (https://github.com/classmethod-aws/gradle-aws-plugin/blob/develop/build.gradle) when you apply this plugin in your own build the aws dependencies will be downloaded and available to your build.