我定义了一些Spring契约,并使用gradle verifierStubsJar打包到jar中。我想用弹簧云契约存根转轮罐运行那个罐子中的存根。我不希望将存根jar发布到工件存储库(如Artifactory或本地Maven存储库)。我只想查存根。如何将包含存根的罐子的位置传递给存根流口瓶?
发布于 2020-01-17 15:56:25
如果你使用gradle generateClientStubs
curl -Lo stub-runner.jar https://search.maven.org/remotecontent?filepath=org/springframework/cloud/spring-cloud-contract-stub-runner-boot/2.2.1.RELEASE/spring-cloud-contract-stub-runner-boot-2.2.1.RELEASE.jar
java -Djava.security-egd=/dev/./urandom -Dstubrunner.repositoryRoot=stubs://file://absolute/path/to/build/stubs -Dstubrunner.ids=com.company-contract:stubs:8081 -Dstubrunner.stubs-mode=REMOTE -jar stub-runner.jar如果你使用gradle verifierStubsJar
curl -Lo stub-runner.jar https://search.maven.org/remotecontent?filepath=org/springframework/cloud/spring-cloud-contract-stub-runner-boot/2.2.1.RELEASE/spring-cloud-contract-stub-runner-boot-2.2.1.RELEASE.jar
java -cp stub-runner.jar:build/libs/my-contract-stubs.jar -Djava.security-egd=/dev/./urandom -Dstubrunner.ids=com.company:my-contract:stubs:8081 -Dstubrunner.stubs-mode=CLASSPATH org.springframework.boot.loader.JarLauncher抓到:
gradle generateClientStubs时,不要忘记存根目录的绝对URI中的前导斜杠。例如stubs://file:///User/me/my-contracts-project/build/stubs。-Dserver.port开始的端口。发布于 2020-01-16 17:17:06
如果你读了这些文档,你会发现这个部分的https://cloud.spring.io/spring-cloud-contract/reference/html/project-features.html#features-stub-runner-stubs-protocol
与从Artifactory / Nexus或Git中选择存根或契约定义不同,您只需指向驱动器或类路径上的位置即可。这在多模块项目中尤其有用,其中一个模块希望重用来自另一个模块的存根或契约,而不需要实际安装本地maven存储库中的存根或契约来将这些更改提交到Git。 为了实现这一点,只要在stubs或Spring协议插件中设置存储库根参数时,就可以使用Stub :// protocol。 在本例中,已成功构建了生产者项目,并在目标/存根文件夹下生成存根。作为消费者,可以设置stubs,使用存根://协议从该位置选择存根。 @AutoConfigureStubRunner( stubsMode = StubRunnerProperties.StubsMode.REMOTE,repositoryRoot =repositoryRoot ids =“com.示例:some”) 契约和存根可以存储在一个位置,其中每个生产者都有自己的专用文件夹,用于契约和存根映射。在该文件夹下,每个使用者都可以有自己的设置。要使Stub从所提供的ids中找到专用文件夹,可以传递一个属性根. find -producer=true或一个系统属性stubrunner.两性. @AutoConfigureStubRunner( stubsMode = StubRunnerProperties.StubsMode.REMOTE,repositoryRoot =repositoryRoot=“com.示例:stubsMode”,properties=“stus.find-producer=true”)
发布于 2022-01-25 15:55:52
经过了大量的探索和挣扎,这对我来说很管用。
将此添加到生产者端build.gradle中
configurations {
// create a configuration that other modules can use
contractStubs {
canBeResolved = false
canBeConsumed = true
}
}
artifacts {
// link the stub jar to the configuration
contractStubs(verifierStubsJar)
}将其添加到消费者端build.gradle中
dependencies {
testImplementation project(path: ':some-path:probucer-dir', configuration: 'contractStubs')
}有关更多信息,请参见:publications.html
https://stackoverflow.com/questions/59774232
复制相似问题