Graph validation is a powerful feature which allows for the enforcement of rules, based on the graph data itself, upon the project as a whole. This can be used to enforce architectural structures within the project (e.g., architectural layer restrictions) or to enforce specific best practices, as defined by the project team.
Graph validation is defined in terms of GraphValidationRule implementations. Each rule is defined by specifying a set of conditions which must be met which indicate a violation of the rule. The conditions are specified in a manner similar to hamcrest matchers, allowing for complex and custom conditions to be specified.
For an example, please refer to the sample project's rule definitions.
Rule implementations are registered with the validation extension on the graphAnalytics
extension.
To validate the project graph for all project modules, run the graphInspection task from the
root project directory. For example, in the sample project we could
run:
$ ./gradlew graphValidationThis will run the graph validation process for all project modules. Since there are no
violations in the sample project, the process should complete successfully. After completion,
manual inspection of the generated report files in each module's build/graphAnalytics
directory can provide some insight into how the plugin works.
This file contains the complete project graph from the perspective of the :app module.
Only project modules which are reachable from the :app module are included in this graph.
This analysis file can be loaded into Gephi for visualization.
This file contains a summary of the validation process for the :app module. Since there
are no violations in the sample project, this file should be mostly empty. If violations
are present, details about the violations - also printed to the console - will be found
here.