Custom Plugin with dependency on external library

I wrote a plugin which has a dependency on the library XY. Now I don’t want the user to have to define a dependency on my plugin as well as on the library XY within the buildscript{} section of the build.gradle file in order to be able to use my plugin.

What is the gradle way to do this? Is there a programmatic way to define the dependency on XY from within my plugin?

If this is a binary plugin and you publish it as a jar file to a repository then if you depend on the XY library in your plugin in the regular way:

dependencies {
    compile "xy:xy:1.0.0"

Gradle will add a transitive dependency on XY to the published artifact metadata (e.g. to the pom if you’re publishing to a Maven repository).