DSL Customization

This section is valid only for the Groovy DSL

You can customize the Spring Cloud Contract Verifier by extending the DSL, as shown in the remainder of this section.spring-doc.cn

Extending the DSL

You can provide your own functions to the DSL. The key requirement for this feature is to maintain the static compatibility. Later in this chapter, you can see examples of:spring-doc.cn

You can find the full example here.spring-doc.cn

Common JAR

The following examples show three classes that can be reused in the DSLs.spring-doc.cn

PatternUtils contains functions used by both the consumer and the producer.spring-doc.cn

ConsumerUtils contains functions used by the consumer.spring-doc.cn

ProducerUtils contains functions used by the producer.spring-doc.cn

Adding a Test Dependency in the Project’s Dependencies

To add a test dependency in the project’s dependencies, you must first add the common jar dependency as a test dependency. Because your contracts files are available on the test resources path, the common jar classes automatically become visible in your Groovy files. The following example show how to test the dependency.spring-doc.cn

Adding a Test Dependency in the Plugin’s Dependencies

Now, you must add the dependency for the plugin to reuse at runtime.spring-doc.cn

Referencing Classes in DSLs

You can now reference your classes in your DSL, as the following example shows.spring-doc.cn

You can set the Spring Cloud Contract plugin up by setting convertToYaml to true. That way, you do NOT have to add the dependency with the extended functionality to the consumer side, since the consumer side uses YAML contracts instead of Groovy contracts.