diff --git a/_includes/build.gradle b/_includes/build.gradle
new file mode 100644
index 0000000000..46c6e1132a
--- /dev/null
+++ b/_includes/build.gradle
@@ -0,0 +1,26 @@
+buildscript {
+ dependencies {
+ classpath "io.spring.gradle:dependency-management-plugin:0.6.0.RELEASE"
+ // if using Stub Runner (consumer side) only remove this dependency
+ classpath "{@= groupId @}:spring-cloud-contract-gradle-plugin:{@= version @}"
+ }
+}
+
+apply plugin: "io.spring.dependency-management"
+apply plugin: 'contract-verifier'
+
+dependencyManagement {
+ imports {
+ mavenBom '{@= groupId @}:spring-cloud-contract-dependencies:{@= version @}'
+ }
+}
+
+dependencies {
+ testCompile '{@= groupId @}:spring-cloud-starter-contract-verifier'
+}
+
+// In this section you define all Spring Cloud Contract Verifier Gradle Plugin properties
+contractVerifier {
+ baseClassForTests = 'com.example.MvcTest'
+ // fully qualified name to a class that will be the base class for your generated test classes
+}
diff --git a/_includes/download_widget.md b/_includes/download_widget.md
index 8bd1ec8df3..bf2b8d11f4 100644
--- a/_includes/download_widget.md
+++ b/_includes/download_widget.md
@@ -11,7 +11,12 @@ Download
your project is with a dependency management system – the snippet below can
be copied and pasted into your build. Need help? See our getting started guides
on building with Maven and
- Gradle.
+ Gradle. The example below is
+ showing how to use the Spring Cloud Contract plugin. In order to use
+ Spring Cloud Contract Stub Runner you just have to use different libraries
+ as presented in the later part of this guide. Of course instead of adding the
+ BOM of the concrete dependency you can add the release train BOM and you won't
+ have to take care of versioning manually.
diff --git a/_includes/pom.xml b/_includes/pom.xml
new file mode 100644
index 0000000000..6faa0f3d3b
--- /dev/null
+++ b/_includes/pom.xml
@@ -0,0 +1,32 @@
+
+
+
+ {@= groupId @}
+ spring-cloud-contract-dependencies
+ {@= version @}
+ pom
+ import
+
+
+
+
+
+ {@= groupId @}
+ spring-cloud-starter-contract-verifier
+ test
+
+
+
+
+
+ {@= groupId @}
+ spring-cloud-contract-maven-plugin
+ {@= version @}
+
+ true
+
+
+ com.example.MvcTest
+
+
+
diff --git a/_includes/widget_templates.html b/_includes/widget_templates.html
index b06f96e9af..c9b26b86f6 100644
--- a/_includes/widget_templates.html
+++ b/_includes/widget_templates.html
@@ -100,6 +100,17 @@
+
+
+
+ {@= repository.id @}
+ {@= repository.name @}
+ {@= repository.url @}
+
+ {@= repository.snapshotsEnabled @}
+
+
+
{% endhighlight %}
@@ -123,6 +134,16 @@ dependencies {
+{% include download_widget.md %}
+
[For a very detailed step by step guide check out the docs](https://cloud.spring.io/spring-cloud-contract/spring-cloud-contract.html#_step_by_step_guide_to_cdc). Below you can find a simplified verstion.
### Server / Producer side
On the server (HTTP) / producer (Messaging) side add the Spring Cloud Contract Verifier Maven / Gradle plugin. Let us assume that our project's group id is `com.example` and artifact id is `http-server`.
-Gradle Setup
+Gradle Setup of the Plugin
```groovy
-buildscript {
- repositories {
- mavenCentral()
- }
- dependencies {
- classpath 'org.springframework.cloud:spring-cloud-contract-verifier-gradle-plugin:${verifier_version}'
- classpath "org.springframework.boot:spring-boot-gradle-plugin:${springBootPlugin}
- }
-}
-
-apply plugin: 'spring-boot'
-apply plugin: 'contract-verifier'
-
-dependencyManagement {
- imports {
- mavenBom "org.springframework.cloud:spring-cloud-contract-dependencies:${verifierVersion}"
- }
-}
-
contractVerifier {
baseClassForTests = 'com.example.MvcTest'
// fully qualified name to a class that will be the base class for your generated test classes
}
-
-dependencies {
- testCompile 'org.springframework.cloud:spring-cloud-starter-contract-verifier'
-}
```
-Maven Setup
+Maven Setup of the Plugin
```xml
- org.springframework.cloud.contract.verifier
- spring-cloud-contract-verifier-maven-plugin
+ org.springframework.cloud
+ spring-cloud-contract-maven-plugin
com.example.MvcTest
```
-and the required test dependencies
-
-```xml
-
-
-
- org.springframework.cloud
- spring-cloud-contract-dependencies
- ${spring-cloud-contract.version}
- pom
- import
-
-
-
-
-
- org.springframework.cloud
- spring-cloud-starter-contract-verifier
- test
-
-```
-
where the `com.example.MvcTest` could look like this (we're assuming that we're using [Rest Assured](http://rest-assured.io/) and we want to do CDC for
a `FraudDetectionController` that you're writing)
@@ -311,8 +269,8 @@ Maven
org.springframework.cloud
- spring-cloud-contract-dependencies
- ${spring-cloud-contract.version}
+ spring-cloud-dependencies
+ ${spring-cloud-dependencies.version}
pom
import
@@ -337,33 +295,37 @@ Gradle
```groovy
buildscript {
- repositories {
- mavenCentral()
- }
- dependencies {
- classpath "org.springframework.boot:spring-boot-gradle-plugin:${springBootPluginVersion}"
- }
+ repositories {
+ mavenCentral()
+ }
+ dependencies {
+ classpath "org.springframework.boot:spring-boot-gradle-plugin:${springBootPluginVersion}"
+ }
}
apply plugin: 'spring-boot'
dependencyManagement {
- imports {
- mavenBom "org.springframework.cloud:spring-cloud-contract-dependencies:${verifierVersion}"
- }
+ imports {
+ mavenBom "org.springframework.cloud:spring-cloud-contract-dependencies:${springCloudDependencies}"
+ }
}
dependencies {
- testCompile "org.springframework.cloud:spring-cloud-contract-wiremock"
- testCompile "org.springframework.cloud:spring-cloud-starter-contract-stub-runner"
+ testCompile "org.springframework.cloud:spring-cloud-contract-wiremock"
+ testCompile "org.springframework.cloud:spring-cloud-starter-contract-stub-runner"
}
```
-The last step is to provide the property for the Stub Runner to automatically download the required stubs. If you're using Spring Boot it's enough to add the following section to your project test properties:
+The last step is to setup Stub Runner in your tests to automatically download the required stubs. To achieve that
+you have to pass the `@AutoConfigureStubRunner` annotation. That annotation has a bunch of properties that you can
+set. If you don't like such an approach you can set those values in your test properties too.
-```yaml
-stubrunner:
- stubs.ids: 'com.example:http-server:+:stubs:8080'
+```java
+@RunWith(SpringRunner.class)
+@SpringBootTest
+@AutoConfigureStubRunner(ids = {"com.example:http-server:+:stubs:8080"}, workOffline = true)
+public class LoanApplicationServiceTests {
```
That way an artifact with group id `com.example`, artifact id `http-server`, in `latest` version, with `stubs` classifier will be registered at port `8080`. Once your test context got booted up, executing the following code will not lead to a 404 because the Spring Cloud Contract Stub Runner will automatically start a WireMock server inside your test and feed it with the stubs generated from the server side.