How can I trigger the afterEvaluate lifecycle event from testcase?

Hi,

I asked this question already on the dev list and Luke referred to this post http://gradle.1045684.n5.nabble.com/why-doesn-t-gradle-project-afterEvaluate-execute-in-my-unit-test-td4512335.html.

I thought it would work, but I had no luck. The event doesn’t get fired. Does anyone have an idea how this could be resolved without using internal or soon-to-be-removed functionality?

Thanks,

Ingo

So what did you see when you called project.evaluate()? Did anything happen?

I am having the same trouble Ingo was having in his original post In my case, I have a Spock test case set up like

setup:
Project project = ProjectBuilder.builder().build()
  project.with {
    apply plugin: 'java'
    apply plugin: 'myplugin'
    project.version = "test.version"
}
  when:
project.evaluate()
  then:
true == project.signing.required

Where ‘myplugin’ among other things applies the maven plugin.

When I run this test, it throws an exception where I attempt to check if signing is required: ‘’’ java.lang.IllegalStateException: Task information is not available, as this task execution graph has not been populated. ‘’’

Even if I add the execution of one of the tasks immediately after ‘project.evaluate()’

setup:
Project project = ProjectBuilder.builder().build()
  project.with {
    apply plugin: 'java'
    apply plugin: 'myplugin'
    project.version = "test.version"
}
  when:
project.evaluate()
project.tasks['jar'].execute()
  then:
true == project.signing.required

I am still given the same exception on the same line.

If I select ‘signArchives’ instead of ‘jar’

setup:
Project project = ProjectBuilder.builder().build()
  project.with {
    apply plugin: 'java'
    apply plugin: 'myplugin'
    project.version = "test.version"
}
  when:
project.evaluate()
project.tasks['signArchives'].execute()
  then:
true == project.signing.required

a new error is thrown: ‘’’ org.gradle.api.GradleException: Could not evaluate onlyIf predicate for task ‘:signArchives’ ‘’’ this time on the line where I execute this task. If I follow the stack trace to the “Caused by” clause, it states the error: ‘’’ Caused by: java.lang.IllegalStateException: Task information is not available, as this task execution graph has not been populated. ‘’’

Luke, I found that you mentioned an upcoming better way for doing these in your original response to Ingo here: http://gradle.1045684.n5.nabble.com/Project-afterEvaluate-question-td4797310.html

Since a year has passed since this question was asked, is there a better answer today?