Need a good example for adding tasks using project instance with new software model

I am trying out the new software model but I am just not getting the concept.
How do I get hold of the project? And should I or is there another way to get what I want?

I want a plug in that only adds one task.
Within the task I want to iterate over all tasks in all subprojects and verify some parameters for each other defined task.

I started by adding something like:

class Example extends RuleSource {
  @Mutate void createTask(ModelMap<Task> tasks, @Path('project') Project project) {
    tasks.create("example") {
      doLast {
        project.subprojects{sub->
          sub.tasks.each {task->

But it seems that ‘project’ is not the path to the project (must have misunderstood something here)
Is this the right approach? And how do I then get the project?

You cannot access the project object in the new software model. You can only address things that live under the model namespace. Gradle needs to know what your Rule’s inputs are and how to build them. The project object is a big, unmanaged blackbox in that regard.

On a more general note, projects should not be “poking” at other project’s internals. The validation should be in the subprojects themselves.

OK, thanks. How would I then go about to do validation on other tasks variable settings? Any suggestions?
My goal is to automatically go through all tasks once they are defined, not necessarily from within a task. The purpose is to validate settings, no alterations.

And how do I know which objects are available under the model namespace?

You can use a @Validate rule. It is not yet described in the user guide as far as I can see, but the JavaDoc is already in place.

The model report will show you everything in the model space.

Got it. First I made an attempt to use an extension but realized that a settings object would give me that possibility to configure a limit. So my example becomes:

@Managed
interface MySettings {
   void setLimit(Long l); Long getLimit()
}

class MyCheck extends RuleSource {
   @Model
   void mysettings(MySettings settings) {
      settings.limit = 10
   }

   @Validate void mycheck(ModelMap<Task> tasks, MySettings settings) {
      long limit = settings.getLimit()
      tasks.withType(MyType).each {task ->
          //check task limit