Reputation: 924
I have written a very simple contract test for HTTP with Spring Cloud Contract. I created the producer which has a contract definition under /src/test/resources/contracts:
package contracts
import org.springframework.cloud.contract.spec.Contract
Contract.make {
request {
method 'GET'
url '/documents/123456789'
headers {
contentType('application/json')
}
}
response {
status OK()
body([
id : 123456789,
status: "VALID"
])
headers {
contentType('application/json')
}
}
}
The producer is a maven module with a definition:
<groupId>com.sample</groupId>
<artifactId>rest-producer</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>rest-producer</name>
I only deployed this producer to my maven local repository. Afterwards, I created a consumer with dependency to the producer stubs:
<dependency>
<groupId>com.sample</groupId>
<artifactId>rest-producer</artifactId>
<version>0.0.1-SNAPSHOT</version>
<classifier>stubs</classifier>
<scope>test</scope>
</dependency>
and I defined a simple test which uses the classpath to search for the stubs:
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.NONE)
@AutoConfigureStubRunner(ids = "com.sample:rest-producer:+:stubs:8080")
class DocumentReaderIntTest {
...
}
When I run this test with maven build via clean install all works fine. However, when I try to run this test via RunConfiguration from Intellij then I get an exception that stubs cannot be found. What should I set up to make this test works from Intellij as well?
Edit: What I found is when I open only the consumer project then on the classpath it has jar from local maven repo:
/Users/adam/.m2/repository/com/sample/rest-producer/0.0.1-SNAPSHOT/rest-producer-0.0.1-SNAPSHOT-stubs.jar
However, when I import the producer in the same project it uses target/classes folder in the classpath so it cannot find contract definition:
/Users/adam/projects/rest-producer/target/classes
Upvotes: 1
Views: 857
Reputation: 11179
Yup that's a known issue with Intellij. Intellij when you reference classpath dependency in a multimodule project will not build the stubs jar but will reference the other module's code directly. Maybe filing an issue to Intellij would make sense?
Upvotes: 1