How to apply a Gradle plugin from another plugin?

I’m trying to incapsulate android plugin in my own plugin, but when I’m trying to apply my plugin build fails with an exception:

A problem occurred evaluating root project ‘myproj’. > Failed to apply plugin [id ‘com.mycomp.build’]

Failed to apply plugin [id ‘android-library’]

Plugin with id ‘android-library’ not found. Here is how I’m applying android plugin inside my own plugin’s implementation:

// build.gradle apply plugin: ‘groovy’

version = ‘1.0’ group = ‘com.mycomp’

dependencies {

compile gradleApi()

compile localGroovy() }

// Build.groovy package com.mycomp

import org.gradle.api.Plugin import org.gradle.api.Project

class Build implements Plugin {

void apply(Project project) {

println ‘Hello from com.mycomp.Build’

project.beforeEvaluate {

buildscript.configurations.classpath +=

‘com.android.tools.build:gradle:1.0.0-rc1’

}

project.configure(project) {

buildscript.repositories.mavenCentral()

apply plugin: ‘android-library’

}

} } For some reason a classpath is not being properly loaded, what am I doing wrong?

A plugin class cannot set its own class path. Instead, plugin dependencies are typically declared in the plugin’s build, and pulled in by Gradle’s transitive dependency resolution.

Thank you, Peter. May I ask you for an example of how to setup a project.build.dependencies.classpath for android plugin in gradle.build?

Not sure what exactly you need. According to your post, the plugin class is in some ‘Build.groovy’, not in ‘build.gradle’. For how to configure an Android build script dependency in ‘build.gradle’, see the Android Gradle plugin docs.