Using a plugin in its own plugin project


(Adarsh Ramamurthy) #1

I am developing a plugin to log tests on console. My plugin is already published in Gradle Central. Now I would like to use this plugin in the plugin project itself by declaring it as

plugins {
    id 'com.adarshr.test-logger' version '1.0.0'

However, when I do that and run ./gradlew clean test, I get the error

FAILURE: Build failed with an exception.

* What went wrong:
A problem occurred configuring root project 'gradle-test-logger-plugin'.
> Could not resolve all files for configuration ':classpath'.
   > Could not resolve com.adarshr:gradle-test-logger-plugin:1.0.0.
     Required by:
         project :
      > Project : declares a dependency from configuration 'classpath' to configuration 'default' which is not declared in the descriptor for project :.

* Try:
Run with --info or --debug option to get more log output.

* Exception is:
org.gradle.api.ProjectConfigurationException: A problem occurred configuring root project 'gradle-test-logger-plugin'.
        at org.gradle.configuration.project.LifecycleProjectEvaluator.addConfigurationFailure(
        at org.gradle.configuration.project.LifecycleProjectEvaluator.doConfigure(

Now I am not sure if what I am trying to do is reasonable but any insight into this would be highly appreciated.

(Schalk Cronjé) #2

Welcome to the club of the self-referencing plugin :wink:

If you need to re-use the same version of the plugin that you are building inside itself, you have two choices.

Firstly the more trivial version is what I described as the Self-Referencing Plugin recipe in Idiomatic Gradle Vol 1. Here is a simple implementation where the Bintray plugin uses the latest version to publich itself to Bintray.

Sometimes you need to add extra stuff to the classLoader in the above case, but in many cases that will just work.

In more complex cases such as the use of the GradleTest plugin to test itself, the above won’t work. In that case you need to use a GradeBuild task to invoke it. Have a look at

and then at

on how this can be accomplished. The former script will invoke the latter script

(Adarsh Ramamurthy) #3

@Schalk_Cronje thanks for your detailed response. Your GroovyScriptEngine approach saved the day. As my plugin depends on an external library, I had to add it to the buildscript section as a classpath dependency.

It all works beautifully now :slight_smile:

(uklance) #4

I’ve solved this a different way, I use a composite build.

Notice that I use version.txt to keep the version in sync in both builds