问题
I am trying to implement stubs in my project but I am getting the follwing error when I try to build it:
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:testCompile (default-testCompile) on project customer-previous-address-older-version: Compilation failure
[ERROR] /archive/target/generated-test-sources/contracts/address/ContractVerifierTest.java:[18,63] cannot find symbol
[ERROR] symbol: class ContractVerifierUtil
[ERROR] location: package org.springframework.cloud.contract.verifier.util
Since the code that the error is occurring is auto-generated, I'm not sure exactly what I can do.
This is the test class that is being auto-generated:
package ie.aib.customer.address;
import com.jayway.jsonpath.DocumentContext;
import com.jayway.jsonpath.JsonPath;
import PreviousAddressBaseTest;
import io.restassured.module.mockmvc.specification.MockMvcRequestSpecification;
import io.restassured.response.ResponseOptions;
import java.io.StringReader;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import org.junit.Test;
import org.w3c.dom.Document;
import org.xml.sax.InputSource;
import static com.toomuchcoding.jsonassert.JsonAssertion.assertThatJson;
import static io.restassured.module.mockmvc.RestAssuredMockMvc.*;
import static org.springframework.cloud.contract.verifier.assertion.SpringCloudContractAssertions.assertThat;
import static org.springframework.cloud.contract.verifier.util.ContractVerifierUtil.*;
public class ContractVerifierTest extends PreviousAddressBaseTest {
@Test
public void validate_shouldReturnPreviousAddress() throws Exception {
// given:
MockMvcRequestSpecification request = given();
// when:
ResponseOptions response = given().spec(request)
.get("/previous-address");
// then:
assertThat(response.statusCode()).isEqualTo(200);
assertThat(response.header("Content-Type")).matches("text/plain;charset=ISO-8859-1");
// and:
String responseBody = response.getBody().asString();
assertThat(responseBody).isEqualTo("Send me something!");
}
}
I added the following dependancy, which I thought would fix the problem, but it hasn't:
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-contract-verifier</artifactId>
</dependency>
回答1:
Try adding spring-cloud-dependencies in the section of our Maven POM. Also make sure spring-cloud.version same everywhere, including for dependency spring-cloud-contract-verifier because i had faced this error due to this.
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>${spring-cloud.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
来源:https://stackoverflow.com/questions/57216741/why-cant-my-class-find-contractverifierutil