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?