Modify model space from build.gradle interacting with another plugin?

I have a “build.gradle” and I want to interact with the model of a plugin I’ve applied (Plugin X).

What’s the correct way to do this? I can’t do it from project space, because the model hasn’t been evaluated yet. I expect that I would need to build a RuleSource plugin in my build.gradle and apply that?

class CustomRules extends RuleSource {

  @Finalize
  void injectMyTask(ModelMap<Task> tasks) {
    tasks.create("hello") {
      doLast {
        println "Hello tomato"
      }
      dependsOn "someTaskInPluginX" //<-- can this be typed?
    }
  }
}

apply plugin: CustomRules

In this case, I’m not sure about a couple of things

  1. Can I make any assumptions about the order @Finalize methods are run? Finalize in pluginX before Finalize in CustomRules?
  2. Would adding @Path("tasks.someTaskInPluginX") to my InjectMyTask method ensure someTaskInPluginX is set up before?
    Should PluginX be doing a better job of managing it’s RuleSource with @Mutate and @Finalize?

In general, setting up dependencies doesn’t matter on ordering since constructing the task graph is the absolute last thing to happen. So in this case, if “someTaskInPluginX” doesn’t exist yet, that’s ok, so long as it exists at some point before execution begins.