Gradle task testing problem with access to private method of task from closure

Dear colleagues, could you help? Is it bug or some convention? I have SomeTask in my own gradle plugin and util method for this task and when try to access to private method from ‘each’ closure gradle thorows MissingMethodException.

As example,

import org.gradle.api.DefaultTask import org.gradle.api.tasks.TaskAction

class TestTask extends DefaultTask {

private boolean func() {

return false

}

@TaskAction

void test () {

new File(’/home’).eachFile {

println func()

}

} }

and specification

import org.gradle.api.* import org.gradle.testfixtures.ProjectBuilder import spock.lang.Shared import spock.lang.Specification import com.myPlugin.tasks.TestTask

class TestTaskSpec extends Specification {

@Shared def Project project

@Shared def Task task

def setupSpec() {

project = ProjectBuilder.builder().build()

task = project.tasks.create(name: ‘testTask’, type: TestTask)

}

def “access to private method of task”() {

when:

task.test()

then:

notThrown(MissingMethodException)

} }

this test produce next exception: Expected no exception of type ‘groovy.lang.MissingMethodException’ to be thrown, but got it nevertheless

at spock.lang.Specification.notThrown(Specification.java:106)

at TestTaskSpec.access to private method of task(TestTaskSpec.groovy:25) Caused by: org.gradle.api.internal.MissingMethodException: Could not find method func() for arguments [] on task ‘:testTask’.

at org.gradle.api.internal.AbstractDynamicObject.methodMissingException(AbstractDynamicObject.java:68)

at org.gradle.api.internal.AbstractDynamicObject.invokeMethod(AbstractDynamicObject.java:56)

at org.gradle.api.internal.CompositeDynamicObject.invokeMethod(CompositeDynamicObject.java:172)

at com.samsung.gradle.tasks.TestTask.test_closure1(TestTask.groovy:15)

at groovy.lang.Closure.call(Closure.java:423)

at groovy.lang.Closure.call(Closure.java:439)

at com.samsung.gradle.tasks.TestTask.test(TestTask.groovy:14)

at TestTaskSpec.access to private method of task(TestTaskSpec.groovy:22)

As I understand but shouldn’t.

In groovy I have written similar code and it’s work fine.

Best regards, Maksym Stavytskyi.