I would like to create my custom Gradle distribution that contains custom plugin. In the distribution, I would like to automatically apply the plugin. So the plugin would be applied by default.
I am trying to simulate this in /customDistribution in samples from gradle -all distribution. This is what I ended up with
// Make the plugin visible to all projects, by including it in the build script classpath.
rootProject {
buildscript {
dependencies {
classpath fileTree(dir: "${initscript.sourceFile.parentFile}/libs", include: '*.jar')
}
}
}
gradle.beforeProject {
plugins.apply 'greeting'
}
And it gives me
Plugin with id 'greeting' not found.
How can one automatically apply custom plugin inside init.d/custom.gradle script under Gradle custom distribution?
I am able to add the standard plugins like ‘maven-publish’, but not the ‘greetings’ plugin. When I apply it directly in build.gradle script, it works fine (and the plugin is taken from my custom distribution).
Looks like I am trying to apply the plugin too soon?
Ah I see what’s happening here. At the point where the configuration hook is called, the project classpath is not yet set up. There is no good hook unfortunately to say “just after the classpath is set up”, so the best we can do here is using afterProject instead of beforeProject.
If you don’t care about the types of that plugin being visible to the project build scripts, then you could also use this alternative, which will resolve the plugin in the context of the init script instead.