How to create a fully functional task for a mock project

Hi everybody,

we are having troubles switching to Gradle 3.0 due to some UnitTests in our project which make use of the task.setProject() method to switch the project of a task to a mocked one.

We create a mock project and mock the config container and stub some method calls to return certain resolved module versions or mocks of file trees. We then switch the project on a created task with this mock and check if our plugin task calls methods with the mocked file trees to make sure the code works as designed.

Since Gradle 3.0 Task.setProject() has been removed and now we try to find another way to test our code. Any suggestions on how we could get a functional task on a mocked project without recreating the complete project object?

Thanks in advance,
Stefan

Sounds overly complicated. Is there a reason you can’t use GradleRunner?

If you want to control the resolved dependencies you can use a local (temp?) folder based maven/ivy/flatdir repository.

Much better to use the real thing in my opinion rather than mocking the universe using internal APIs :smile: