Gradle Test Kit cannot load plugin project's plugin

Congrats release of gradle2.6.

So I tried Gradle TestKit immediately.

But Gradle TestKit cannot load my plugin project’s plugin.

Question

Is there any way to load my plugin project as gradle plguin?


Error Detail

my project has structure as bellow.

src
 + main
 |   + groovy
 |   |   + org
 |   |      + sample
 |   |           + Impl.groovy
 |   |           + model
 |   |               + MyModel.java
 |   + resources
 |         + META-INF
 |              + gradle-plugins
 |                   + sample-plugin.properties
 + test
     + groovy
     |   + org
     |       + sample
     |           + ImplSpec.groovy
     + resources
         + test.gradle

In the test.gradle, which is to be loaded in ImplSpec.groovy as test build script.

apply plugin: 'sample-plugin'

model {
    myModel {
        message = 'Hello TestKit'
    }
}

Impl.groovy is subclass of RuleSource and read MyModel and add task named hello via ModelMap<Task> at @Mutate phase.

ImplSpec.groovy is test using GradleTestKit with Spock.

class ImplSpec extends Specification {
    @Rule
    final TemporaryFolder projectDir = new TemporaryFolder()
    final ClassLoader loader = getClass().classLoader
    File buildFile
    def setup() {
        buildFile = projectDir.newFile('build.gradle')
    }
    def 'hello task outputs message'() {
        given:
        buildFile << loader.getResource('test.gradle').text

        when:
        def result = GradleRunner.create()
                .withProjectDir(projectDir.root)
                .withArguments('hello')
                .build()

        then:
        result.standardOutput.contains('Hello TestKit')
    }
}

And I ran this test, got UnexpectedBuildFailure, saying

* What went wrong:
A problem occurred evaluating root project 'junit3699627952491582960'.
> Plugin with id 'sample-plugin' not found.

if I wrote the contents of Impl.groovy and MyModel.java into test.gradle, it worked fine.

So, I’m wondering how to recognize my gradle plugin. Is there any way to load my plugin into GradleTestKit?

As of Gradle 2.6, the TestKit does not automatically discover plugin classes under test. This functionality is going to be delivered with an upcoming version of Gradle. To make the plugin classes available to the TestKit’s classpath you’ll need to add some more logic to your build. Please have a look at the section “Getting the code under test into the test build” in the user guide. It describes what needs to be done.

Thanks!

I’ll create plugin for TestKit, which generates class automatically load created plugin, in 2 ~ 3 days.

Released plugin for supporting TestKit.

Please see org.mikeneck.gradle-testkit-support-plugin.