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



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”() {





} }

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(

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(

at org.gradle.api.internal.AbstractDynamicObject.invokeMethod(

at org.gradle.api.internal.CompositeDynamicObject.invokeMethod(





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.