au.com.dius:pact-jvm-provider-gradle_2.11:2.1.6

Group / Artifact / Version au.com.dius / pact-jvm-provider-gradle_2.11 / 2.1.6
Namepact-jvm-provider-gradle_2.11
Descriptionpact-jvm-provider-gradle ======================== Gradle plugin for verifying pacts against a provider. The Gradle plugin creates a task `pactVerify` to your build which will verify all configured pacts against your provider. ## To Use It ### For Gradle versions prior to 2.1 #### 1.1. Add the pact-jvm-provider-gradle jar file to your build script class path: ```groovy buildscript { repositories { mavenCentral() } dependencies { classpath 'au.com.dius:pact-jvm-provider-gradle_2.10:2.0.10' } } ``` #### 1.2. Apply the pact plugin ```groovy apply plugin: 'au.com.dius.pact' ``` ### For Gradle versions 2.1+ ```groovy plugins { id "au.com.dius.pact" version "2.1.1" } ``` ### 2. Define the pacts between your consumers and providers ```groovy pact { serviceProviders { // You can define as many as you need, but each must have a unique name provider1 { // All the provider properties are optional, and have sensible defaults (shown below) protocol = 'http' host = 'localhost' port = 8080 path = '/' // Again, you can define as many consumers for each provider as you need, but each must have a unique name hasPactWith('consumer1') { // currently supports a file path using file() or a URL using url() pactFile = file('path/to/provider1-consumer1-pact.json') } // Or if you have many pact files in a directory hasPactsWith('manyConsumers') { // Will define a consumer for each pact file in the directory. // Consumer name is read from contents of pact file pactFileLocation = file('path/to/pacts') } } } } ``` ### 3. Execute `gradle pactVerify` ## Starting and shutting down your provider If you need to start-up or shutdown your provider, you can define a start and terminate task for each provider. You could use the jetty tasks here if you provider is built as a WAR file. ```groovy // This will be called before the provider task task('startTheApp') << { // start up your provider here } // This will be called after the provider task task('killTheApp') << { // kill your provider here } pact { serviceProviders { provider1 { startProviderTask = startTheApp terminateProviderTask = killTheApp hasPactWith('consumer1') { pactFile = file('path/to/provider1-consumer1-pact.json') } } } } ``` Following typical Gradle behaviour, you can set the provider task properties to the actual tasks, or to the task names as a string (for the case when they haven't been defined yet). ## Modifying the requests before they are sent Sometimes you may need to add things to the requests that can't be persisted in a pact file. Examples of these would be authentication tokens, which have a small life span. The Pact Gradle plugin provides a request filter that can be set to a closure on the provider that will be called before the request is made. This closure will receive a Map with all the requests attributes defined on it. ```groovy pact { serviceProviders { provider1 { requestFilter = { req -> // Add an authorization header to each request req.headers['Authorization] = 'OAUTH eyJhbGciOiJSUzI1NiIsImN0eSI6ImFw...' } hasPactWith('consumer1') { pactFile = file('path/to/provider1-consumer1-pact.json') } } } } ``` ## Project Properties The following project properties can be specified with `-Pproperty=value` on the command line: |Property|Description| |--------|-----------| |pact.showStacktrace|This turns on stacktrace printing for each request. It can help with diagnosing network errors| |pact.filter.consumers|C
Last modified2014-11-24 08:13:37 UTC
URL https://github.com/DiUS/pact-jvm
Repository URL http://repo1.maven.org/maven2/au/com/dius/pact-jvm-provider-gradle_2.11/2.1.6/
Packaging jar
POM File View
Effective POM File View
Dependency tag
<dependency>
  <groupId>au.com.dius</groupId>
  <artifactId>pact-jvm-provider-gradle_2.11</artifactId>
  <version>2.1.6</version>
</dependency>
'au.com.dius:pact-jvm-provider-gradle_2.11:jar:2.1.6'
<dependency org="au.com.dius" name="pact-jvm-provider-gradle_2.11" rev="2.1.6" />
@Grapes(@Grab(group='au.com.dius', module='pact-jvm-provider-gradle_2.11', version='2.1.6'))
compile 'au.com.dius:pact-jvm-provider-gradle_2.11:2.1.6'
libraryDependencies += "au.com.dius" % "pact-jvm-provider-gradle_2.11" % "2.1.6"
Repository tag
  <repository>
    <id>central</id>
    <url>http://repo1.maven.org/maven2/</url>
  </repository>
Packages

au.com.dius.pact.provider.gradle