How can I delay applying a plugin until after a task has been run?

Is there any way to delay applying a plugin until after a certain task has been run? I have a task that generates content which a plugin needs in order for it to initialise, and currently the solution is to generate the content to a separate directory and then launch a new GradleBuild task that performs the rest of the work. The main problem is that it’s not possible to see from the main script what tasks are available in the sub-dir script, and running multiple unrelated tasks will require re-launching the sub-dir build multiple times.

Example: I have a task chain like this: init -> build -> publish, where the build and publish steps cannot be configured until after init has been run, as the init step generates a file which is evaluated by the plugin that provides the build and publish tasks.

Unfortunately I cannot currently alter the requirement that files get generated by the init script. I can modify the plugin, but I would rather not.

This isn’t possible, as plugins run in an earlier phase (configuration phase) than tasks (execution phase). I don’t have enough information to recommend a solution.