Package org.gradle.model

# Class RuleSource

java.lang.Object
org.gradle.model.RuleSource

Direct Known Subclasses:
  `AssemblerLangPlugin.Rules`, `BinaryBasePlugin.Rules`, `CLangPlugin.Rules`, `ComponentBasePlugin.PluginRules`, `ComponentModelBasePlugin.PluginRules`, `ComponentModelBasePlugin.PluginRules.AttachInputs`, `CppLangPlugin.Rules`, `CUnitConventionPlugin.Rules`, `CUnitPlugin.Rules`, `GoogleTestConventionPlugin.Rules`, `GoogleTestPlugin.Rules`, `LanguageBasePlugin.Rules`, `NativeBinariesTestPlugin.Rules`, `NativeComponentModelPlugin.Rules`, `ObjectiveCLangPlugin.Rules`, `ObjectiveCppLangPlugin.Rules`, `PublishingPluginRules`, `TestingModelBasePlugin.Rules`, `VisualStudioPluginRules.VisualStudioExtensionRules`, `VisualStudioPluginRules.VisualStudioPluginProjectRules`, `VisualStudioPluginRules.VisualStudioPluginRootRules`, `WindowsResourceScriptPlugin.Rules`

@Incubating public class RuleSource extends Object
A marker type for a class that is a collection of rules.

A rule source is not used like a regular Java object. It is a stateless container of methods and possibly constants.

Please consult the "Rule based model configuration" chapter of the Gradle User Manual for general information about "rules".

## Rule methods

Each method that is annotated with one of the following is considered a rule:

- `Model`
- `Defaults`
- `Mutate`
- `Finalize`
- `Validate`
- `Rules`
- `ComponentType`
- `ComponentBinaries`
- `BinaryTasks`

Each annotation specifies the type of the rule, which affects when it will be executed.

The following constraints apply to all rule methods:

- A method may only be annotated by at most one of the above annotations.
- A rule method may be `static` or not; it makes no difference.
- A rule method cannot be generic (i.e. cannot have type parameters).
- With the exception of `Model` methods, all methods must have at least one parameter.
- With the exception of `Model` methods, all methods must have a `void` return type.

See `Model` for information on the significance of the return type of a `Model` method.

### Subjects and inputs

Method rules declare the subject and any inputs as parameters to the method. With the exception of `Model` methods, the subject of the rule is the, required, first parameter and all subsequent parameters are inputs. For a non-void `Model` method, the subject (i.e. model element being created) is the return object. For a void `Model` method, the subject is the first method parameter.

The `Path` annotation can be placed on any parameter (except the subject of `Model` rules) to indicate the model element to bind to. If there is no `Path` annotation, a "by-type" binding will be attempted. The binding scope is determined by how the rule source is applied.

## General class constraints

Along with the constraints on individual rule methods by their associated annotation, the following are general constraints of rule source implementations:

- Constructors are not allowed.
- Inheritance hierarchies are not allowed (i.e. all rules sources must directly extend `RuleSource`).
- Instance variables are not allowed.
- Non-final static variables are not allowed (i.e. constants are allowed).
- Methods cannot be overloaded.
- Implementations cannot be generic (i.e. cannot use type parameters).

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `RuleSource()`

- ## Method Summary

  ### Methods inherited from class java.lang.Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## Constructor Details

  - ### RuleSource

    public RuleSource()