How to apply custom plugin I am developing in gradlerrunner


(John Scancella) #1

I want to test applying my custom plugin in a test, but every time I do it says it can’t find it. In the example it shows applying a plugin that already exists. How do I apply it if it only exists locally in my project?


(uklance) #2

Yes, this is one of the “messy” things about testkit that I’m hoping is cleaner to do in future (Jacoco bootstrapping is the other “messy” thing)

See here where I create a testkit-classpath.txt file and add the folder to the testRuntime configuration. And here where I read the testkit-classpath.txt and bootstrap the gradle build with it.

This could also be done using system properties instead of a file but I prefer file based approach because I can run in my IDE without needing gradle (assuming I’ve run once in gradle first)


(Benjamin Muschko) #3

Please refer to the section Automatic injection with the Java Gradle Plugin Development plugin in the user guide. Make sure that your GradleRunner instance calls the method withPluginClasspath(). The build script under test must use the plugin DSL to apply your plugin under test.

@Lance Can you explain what you find “messy” about the approach? It requires very little configuration. Are you just referring to the integration with JaCoCo?

I created an issue regarding the integration with JaCoCo. Contributions welcome!


(uklance) #4

I tried GradleRunner.withPluginClasspath(...) initially but it wasn’t working. After looking at the example I think my problem was using apply plugin 'x' instead of plugins { id 'x' }

I’ve just made a change here to remove my manual testkit classpath config and instead use java-gradle-plugin and GradleRunner.withPluginClasspath(). It’s much cleaner now


(Benjamin Muschko) #5

I am planning to state the mandatory configuration more clearly in the user guide: https://github.com/gradle/gradle/issues/1231