0
votes

I have established Spring cloud contract between two microservices in my project successfully. Everything was good until yesterday.

On consumer side, I am referencing the latest version of stubs like below:

@AutoConfigureStubRunner(ids = {"com.example:http-server-dsl:+:stubs:8080"})

But this causes problem in some cases where the producer side reverted their latest version and switched back to previous version.

Or

somehow there is a situation that the jar that contains current stubs has a lower version than the latest version in maven repo.

Is there a way in Spring cloud contract to do either one of the following?

1) configure the consumer side to pick up the current project version (referring to project version in pom.xml) instead of the latest version from maven repo?

Or

2) configure the producer side to have a static version of stubs jar but keep dynamic version of other project jars. This would allow the consumer side to refer to the same static version of stubs jar

I read the documentation https://cloud.spring.io/spring-cloud-static/spring-cloud-contract/2.1.1.RELEASE/single/spring-cloud-contract.html#_jar_versioning but it did not help

2

2 Answers

2
votes

You can play around with the provided version. We give + to always download the latest. You can set a concrete value e.g. 2.1.1.RELEASE. You can also set ranges. All in all we're using Ivy underneath so you can check out the rules of Ivy http://ant.apache.org/ivy/history/latest-milestone/settings/version-matchers.html

1) configure the consumer side to pick up the current project version instead of the latest one?

What does current mean? Is it the latest? Latest release? If it's the latest release pick + but point to the repo that contains release versions only without snapshots.

I read the documentation https://cloud.spring.io/spring-cloud-static/spring-cloud-contract/2.1.1.RELEASE/single/spring-cloud-contract.html#_jar_versioning but it did not help

What is missing in this section? You asked about static stubs, we describe it there too @AutoConfigureStubRunner(ids = {"com.example:http-server-dsl:2.1.1:stubs:8080"}).

1
votes

Following worked (for maven project).

Step1: Instead of specifying the ids in @AutoConfigureStubRunner, we can provide it inside application.properties file like below (notice @project.version@, this refers to maven project version )

stubrunner.ids=com.example:http-server-dsl:@project.version@:stubs:8080

Step2: To be able to use @project.version@ in properties file, add the following in build section of pom.xml:

 <resources>
            <resource>
                <directory>src/main/resources</directory>
                <filtering>true</filtering>
            </resource>
        </resources>

And in plugins section:

   <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-resources-plugin</artifactId>
        <version>${mvn-resources-plugin.version}</version>
        <configuration>
            <delimiters>
                <delimiter>@</delimiter>
            </delimiters>
            <useDefaultDelimiters>false</useDefaultDelimiters>
        </configuration>
    </plugin>