Validation rules applied to project categories

(Brian Keyser) #1

Suppose that your build project is composed of projects where projects may be placed into distinct project categories. For example, a non-root project may be responsible for downloading and managing web resources (artifacts project). The other non-root projects are responsible for packaging a set of resources (packaging projects) along with the web resources of the other project category.

Rules can be developed for each category of project through the application of a plugin. When applying plugins, I have noticed that the tasks remain separate. In other words, tasks added to the ModelMap of a project category are not available as tasks to the other project category. However, I have noticed that the same does not apply to validation rules. For example, if a plugin for a project category defines a set of validation rules then those rules are applied to the other project category. Why are tasks applied differently than rules?

In this example, the artifact project does not need to know about the concept of a module. However, a packaging project would. If a rule is applied through a plugin

abstract class PackagingRules
    extends RuleSource {

    void moduleValidation(ModuleValidation validation, Module module) {
abstract class ModuleValidation
    extends RuleSource {

    void validateModule(Module module) {
        module.with {
            assert groupId && artifactId && version && type

then the rule is applied to all the projects, including the root project which results in a model validation failure as the root project is not aware of Module.

What is the recommended approach for developing rules for a subset of a model?

(Brian Keyser) #2

Similar to the problem described above, I am wondering about tasks. For example, given the same context as above, how are dependencies declared between tasks. Plugins may be selectively applied, but then how are tasks in other projects referenced?