-
Notifications
You must be signed in to change notification settings - Fork 317
Description
Preamble
My setup contains the following modules:
| Module name | Corresponding module in the samples | Description |
|---|---|---|
| my-contracts | beer_contracts | Module with contracts. |
| my-producer | producer_with_external_contracts | Producer of the API. |
| my-consumer | - | Consumer of the API. |
I wanted to execute the Spring Cloud Contract tests during the build with contractsMode CLASSPATH.
For that reason, I created an aggregator containing these three modules und executed mvn clean test.
In the samples, the beer_contracts module with external contracts does not provide the artifact with the classifier stubs.
I choose another approach for my project.
The module my-contracts does provide the artifact with the classifier stubs.
The modules my-consumer and my-producer do not know each other but the API and the module my-contracts.
Issue
To demonstrate how Spring Cloud Contract works with external contracts, the samples contain already the modules beer_contracts and producer_with_external_contracts.
This works with contractsMode LOCAL but not with contractsMode CLASSPATH.
In my project this has a couple of reasons:
After setting contractsMode to CLASSPATH in my-producer the following problems occur:
-
No stubs were found on classpath for [com.example:beer-contracts]I had to add the dependency of
beer-contractsto the plugin dependencies inproducer_with_external_contractslike this:<plugin> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-contract-maven-plugin</artifactId> <version>${spring-cloud-contract.version}</version> <extensions>true</extensions> <configuration> ... <contractDependency> <groupId>de.demo</groupId> <artifactId>my-contracts</artifactId> <classifier>stubs</classifier> </contractDependency> <contractsMode>CLASSPATH</contractsMode> ... </configuration> <dependencies> <dependency> <groupId>de.demo</groupId> <artifactId>my-contracts</artifactId> <version>0.0.1.BUILD-SNAPSHOT</version> <classifier>stubs</classifier> </dependency> </dependencies> </plugin>
The next error message is the following:
-
[ERROR] Unresolveable build extension: Plugin org.springframework.cloud:spring-cloud-contract-maven-plugin:2.1.3.BUILD-SNAPSHOT or one of its dependencies could not be resolvedNormally Maven will resolve the dependencies of modules and plugins during the build.
The problem here is the<extensions>true</extensions>tag.
I guess that dependencies of extensions have to be available at the time the build starts and can not be resolved during the build.
To fix it, I just had to include thespring-cloud-contract-maven-pluginto the extensions and remove the<extensions>true</extensions>tag (or set it to false):<build> <extensions> <extension> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-contract-maven-plugin</artifactId> <version>${spring-cloud-contract.version}</version> </extension> </extensions> <plugins> ... <plugin> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-contract-maven-plugin</artifactId> <version>${spring-cloud-contract.version}</version> <extensions>false</extensions> <configuration> ... <contractsMode>CLASSPATH</contractsMode> </configuration> <dependencies> <dependency> <groupId>de.demo</groupId> <artifactId>my-contracts</artifactId> <version>0.0.1.BUILD-SNAPSHOT</version> <classifier>stubs</classifier> </dependency> </dependencies> </plugin> </plugins> </build>
After these fixes, the build and all Spring Cloud Contract tests run properly.
Now I have the following questions:
-
Is my approach with
my-contractsand artifact with classifierstubsused in consumer and producer by Spring Cloud Contracts intended? -
How would a setup look with given modules
beer_contractsandproducer_with_external_contractswithcontractsMode CLASSPATH?
Just adapting my fixes does not work.