我是Spring-Cloud-contract的新手。試圖配置我的版本,我得到錯誤。Spring Cloud Contract中生成的測試失敗
這裏是我的項目結構
項目
| ==>模塊
我有類路徑在我的項目的build.gradle
項目生成文件
buildscript {
dependencies {
classpath "org.sonarsource.scanner.gradle:sonarqube-gradle-plugin:2.2.1"
classpath("org.springframework.boot:spring-boot-gradle-plugin:1.5.4.RELEASE")
classpath "org.springframework.cloud:spring-cloud-contract-gradle-plugin:1.1.3.RELEASE"
}
apply from: "$projectDir/gradle/app/springcloud.gradle" //Gradle build file in module
}
模塊裝配文件中的以下相關
apply plugin: 'groovy'
apply plugin: 'spring-cloud-contract'
apply plugin: 'org.springframework.boot'
dependencies {
//Spring cloud contract dependencies
compile('org.springframework.boot:spring-boot-starter-actuator')
compile('org.springframework.boot:spring-boot-starter-web')
testCompile('org.springframework.boot:spring-boot-starter-test')
testCompile('org.springframework.cloud:spring-cloud-starter-contract-verifier')
testCompile "org.springframework.cloud:spring-cloud-starter-contract-stub-runner"
testCompile "com.jayway.restassured:rest-assured:2.5.0"
testCompile "com.jayway.restassured:spring-mock-mvc:2.5.0"
}
//Spring cloud contract dependency management
dependencyManagement {
imports {
mavenBom "org.springframework.cloud:spring-cloud-dependencies:Dalston.RELEASE"
}
}
我有一個時髦的fi le有一個post請求和一個響應。當我做gradle build
時,測試是自動生成的,但我的構建感覺。
C:\Users\user\Projects\myProject\module\build\generated-test-sources\contracts\org\springframework\cloud\contract\verifier\tests\ContractVerifierTest.java:3: error: cannot find symbol
import com.jayway.jsonpath.DocumentContext;
^
symbol: class DocumentContext
location: package com.jayway.jsonpath
C:\Users\user\Projects\myProject\module\build\generated-test-sources\contracts\org\springframework\cloud\contract\verifier\tests\ContractVerifierTest.java:28: error: cannot find symbol
DocumentContext parsedJson =
JsonPath.parse(response.getBody().asString());
^
我做錯了什麼?在我使用的版本中是否有任何不匹配?
很有可能您的版本不匹配。請查看此回購https://github.com/spring-cloud-samples/spring-cloud-contract-samples/blob/master/producer/build.gradle與春季雲合同樣本,並更新您的項目看起來相同 –
我正在將Spring雲合同應用於現有項目。看起來項目已經在其依賴項中引導了spring。我將嘗試查看依賴關係樹來找出衝突。 – vkrams
@MarcinGrzejszczak我的項目使用'springBootversion = 1.4.3.RELEASE',不能更改或升級它。哪個'spring-cloud-contract-gradle-plugin'與這個版本兼容?另外我使用'spring-cloud-dependencies:Camden.SR7'這是否?感謝您的幫助 – vkrams