How to specify external dependencies inside of custom plugin?


(dtserekhman) #1

Hi,

I’m trying to specify the following dependency inside of my custom task definition, which in its turn is a part of the custom plugin:

project.buildscript.dependencies {
            classpath "org.apache.commons:commons-io:1.3.2"
        }

The above does not take effect. I’m getting java.lang.NoClassDefFoundError when trying to reference class from the above library in my plugin. I also tried various variations of the above, such as:

project.dependencies {
            classpath "org.apache.commons:commons-io:1.3.2"
        }

and

project.dependencies {
            runtime "org.apache.commons:commons-io:1.3.2"
        }

But nothing seems to work. It does work, however, if I specify this dependency in my external build.gradle script that applies my plugin, but the whole point is to have all the dependencies, which plugin depends on, to be encapsulated inside of the plugin itself.

I also found this link on this topic, but I’m still having problems:

http://stackoverflow.com/questions/10081299/creating-a-gradle-plugin-with-a-dependency-on-another-external-plugin

Can anyone please provide any specific example on how to do this?

Thank you! Dmitriy.


(Peter Niederwieser) #2

‘buildscript { … }’ only works for build scripts. When you ship precompiled plugin/task classes as a Jar, you just need to publish the Jar to a Maven or Ivy repository, and transitive dependency management will do the rest (just as for any other Maven or Ivy module).


(dtserekhman) #3

Yep, after I specified this dependency in the build.gradle used for generating and publishing jar to maven repository, the generated .pom file which gets uploaded to the repository with the .jar included the new dependency, and this resolved the problem during runtime that referenced this .jar

Thank you! Dmitriy.