Given: gradle version is 2.2.1
Task example: <code> class TestTask extends DefaultTask { PegDownProcessor markdown = new PegDownProcessor(Extensions.ALL);
@TaskAction
private void generateDocs() {
String str = markdown.markdownToHtml '##Hello'
println str
}
} </code> I have written task like that and added by plugin. Plugin just adds task with some name with current type of task. <code> void apply(Project project) { project.tasks.create('generateDocs', TestTask) } </code> 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: <code> compile gradleApi() compile localGroovy() compile group: 'org.pegdown', name: 'pegdown', version: '1.4.2' testCompile 'org.spockframework:spock-core:0.7-groovy-2.0' </code> Doesn't work even with empty spec: <code> class TestPluginSpec extends Specification {
} </code> and produce next stacktrace: <code> 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 </code>
When I have changed spock version to:
<code>
testCompile 'org.spockframework:spock-core:1.0-groovy-2.3-SNAPSHOT'
</code>
and add repositories:
<code>
repositories{
maven { url 'http://repo1.maven.org/maven2' }
maven { url 'http://oss.sonatype.org/content/repositories/snapshots' }
}
</code>
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<String>) all works fine. I can move new PegDownProcessor(Extensions.ALL)
to method and test will pass too. As example:
<code>
lass TestTask extends DefaultTask {
PegDownProcessor markdown
@TaskAction
private void generateDocs() {
markdown = = new PegDownProcessor(Extensions.ALL)
String str = markdown.markdownToHtml '##Hello'
println str
}
} </code>
For both cases Junit and Spock I have used one setup method of tests with body: <code> void setup() { project = ProjectBuilder.builder().build() project.apply plugin: TestPlugin } </code>
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**
Status: New
Labels:
Type-Defect
Module-Core