Is there a way to trigger afterEvaluate actions on a Project obtained from ProjectBuilder after we have the Project reference (since we need the Project to perform the configuration)?
The general guidance has been that ProjectBuilder is designed for lower level testing (on the pyramid) to verify direct manipulation of the project model.
When you start using Project#afterEvaluate, you’re hooking into the build lifecycle, which doesn’t really exist outside the context of running a build. At that point, the expectation is you’re running more of a functional test with TestKit.
Can you do enough to get the hooks to run on the current version? I haven’t tried, but I believe you’d be very dependent on calling internals that can change between versions to get close to what really happens.
Should you? Eh, I’d structure my tests differently such that my ProjectBuilder tests are only focused on lower level concerns.
Yes, you can just call project.evalute(). If you are writing your tests in type-checked manner don’t forget to cast to ProjectInternal. As mentioned, it’s a bit nasty, but realistically, the use of afterEvaluate { } is ubiquitous and unavoidable in many cases so at least using evaluate() you can test that code w/o resorting to an integration test.