Given: gradle version is 2.2.1
Task example:
class TestTask extends DefaultTask {
PegDownProcessor markdown =
new PegDownProcessor(Extensions.ALL);
@TaskAction
private void generateDocs() {
String str = markdown.markdownToHtml '##Hello'
println str
}
}
I have written task like that and added by plugin. Plugin just adds task with some name with current type of task.
void apply(Project project) {
project.tasks.create('generateDocs', TestTask)
}
When have I written test with JUnit all was fine but when I have tried to use spock, I had a lot of problem.
dependncies for spock in buildSRC:
compile gradleApi()
compile localGroovy()
compile group: 'org.pegdown', name: 'pegdown', version: '1.4.2'
testCompile 'org.spockframework:spock-core:0.7-groovy-2.0'
Doesn’t work even with empty spec:
class TestPluginSpec extends Specification {
}
and produce next stacktrace:
com.test.gradle.plugin.TestPluginSpec > initializationError FAILED
org.spockframework.util.InternalSpockError
Caused by: java.lang.ExceptionInInitializerError at TestPluginSpec.groovy:-1
Caused by: groovy.lang.GroovyRuntimeException at TestPluginSpec.groovy:-1
When I have changed spock version to:
testCompile 'org.spockframework:spock-core:1.0-groovy-2.3-SNAPSHOT'
and add repositories:
repositories{
maven { url 'http://repo1.maven.org/maven2' }
maven { url 'http://oss.sonatype.org/content/repositories/snapshots' }
}
I couldn’t instantiate my task and as I understood this problem related to pegdown processor instantiation, because for another type of fields(String, List) all works fine. I can move ‘new PegDownProcessor(Extensions.ALL)’ to method and test will pass too. As example:
lass TestTask extends DefaultTask {
PegDownProcessor markdown
@TaskAction
private void generateDocs() {
markdown =
=
new PegDownProcessor(Extensions.ALL)
String str = markdown.markdownToHtml '##Hello'
println str
}
}
For both cases Junit and Spock I have used one setup method of tests with body:
void setup() {
project = ProjectBuilder.builder().build()
project.apply plugin: TestPlugin
}
if I use gradle 1.9 and ‘testCompile ‘org.spockframework:spock-core:0.7-groovy-1.8’’ in both cases everything is good. So I think this problem depends on version of spock and groovy in gradle. Can you help me how I should use spock with gradle version 2.0 and higher?
As I have tested this problem related to all version of gradle 2.x and last release candidate gradle 2.3-rc-3**