Model rule and inheritance of model by subprojects


(Brian Keyser) #1

With extensions, the domain model defined in the parent could be modified by a child project. I have been experimenting with model rules and noticed that the model is not passed along to the subprojects. I have also noticed that model elements defined in the enclosing project are not available to a subproject (for example, using the path syntax of $.entity). Is the model or its elements of an enclosing project available to a subproject? If so, how would they be exposed to the child projects?

For example, in the enclosing parent our model is similar to the following

model {
    packaging {
        repository {
            id = 'foo'
            url = 'https://...'
        }
    }
}

and in the enclosing project the model is defined as

model {
    packaging {
        artifact {
            groupId = 'org....'
            artifactId = 'artifact'
            version = '1.0.0'
        }
    }
}
```

Using extensions with similar elements, the domain model for the subproject would contain the definitions for repository and artifact.  However, with model rules, the models appear to be independent.  Does this mean that the same model element in repository would have to be duplicated to each subproject?

(Brian Keyser) #2

The solution, I believe, is to include the model definition in the subprojects specification. For example,

subprojects {
     apply plugin: 'MyPluginRules'

     model {
         packaging {
             ...
         }
     }
}

This allowed a subproject to extend the model to include the artifact.