如何构建 Spring Cloud Contract

在 Windows 上克隆仓库

在 Windows 上克隆此项目时,git 仓库中的某些文件路径可能会超过 Windows 的最大文件路径限制 255 个字符,这可能导致仓库检出不正确(可能是不完整的)。

要解决此问题,您可以将 core.longPaths 属性设置为 true 或克隆 Spring Cloud Contract 仓库。

要将 core.longPaths 属性设置为 true,您有三种选择

  • 为机器的所有用户更改(需要管理员权限)

git config --system core.longPaths true
git clone https://github.com/spring-cloud/spring-cloud-contract.git
  • 为当前用户更改(无需管理员权限)

git config --global core.longPaths true
git clone https://github.com/spring-cloud/spring-cloud-contract.git
  • 仅针对此仓库更改(管理员权限取决于仓库克隆的位置)

git clone -c core.longPaths=true https://github.com/spring-cloud/spring-cloud-contract.git
您的 IDE 需要安装所有必要的 Groovy 插件才能正确解析源文件。例如,在 Intellij IDEA 中,同时安装 Eclipse Groovy Compiler Plugin 和 GMavenPlus Intellij Plugin 可以正确导入项目。
Spring Cloud Contract 会构建 Docker 镜像。请记住安装 Docker。
如果您想在离线模式下运行构建,必须安装 Maven 3.5.2+。

项目结构

以下列表显示了 Spring Cloud Contract 的文件夹结构

├── config
├── docker
├── samples
├── scripts
├── specs
├── spring-cloud-contract-dependencies
├── spring-cloud-contract-shade
├── spring-cloud-contract-starters
├── spring-cloud-contract-stub-runner
├── spring-cloud-contract-stub-runner-boot
├── spring-cloud-contract-tools
├── spring-cloud-contract-verifier
├── spring-cloud-contract-wiremock
└── tests

以下列表描述了项目结构中的每个顶层文件夹

  • config:包含 Spring Cloud Release Tools 自动化发布过程设置的文件夹

  • docker:包含 docker 镜像的文件夹

  • scripts:包含使用 Maven、Gradle 构建和测试 Spring Cloud Contract 的脚本

  • specs:包含合同 DSL 的规范。

  • spring-cloud-contract-dependencies:包含 Spring Cloud Contract BOM

  • spring-cloud-contract-shade:插件使用的阴影依赖

  • spring-cloud-contract-starters:包含 Spring Cloud Contract Starters

  • spring-cloud-contract-spec:包含规范模块(包含合同概念)

  • spring-cloud-contract-stub-runner:包含 Stub Runner 相关模块

  • spring-cloud-contract-stub-runner-boot:包含 Stub Runner Boot 应用

  • spring-cloud-contract-tools:Spring Cloud Contract Verifier 的 Gradle 和 Maven 插件

  • spring-cloud-contract-verifier:Spring Cloud Contract Verifier 功能的核心

  • spring-cloud-contract-wiremock:所有 WireMock 相关功能

  • tests:针对不同消息技术的集成测试

命令

要构建核心功能以及 Maven 插件,您可以运行以下命令

./mvnw clean install -P integration

调用该函数会构建核心、Maven 插件和 Gradle 插件。

要只构建 Gradle 插件,您可以运行以下命令

cd spring-cloud-contract-tools/spring-cloud-contract-gradle-plugin
./gradlew clean build

有用的脚本

我们提供了一些有用的脚本来构建项目。

要并行构建项目(默认使用四个核心,但您可以更改),请运行以下命令

./scripts/parallelBuild.sh

要使用八个核心,请运行以下命令

CORES=8 ./scripts/parallelBuild.sh

要构建项目而不运行任何集成测试(默认使用一个核心),请运行以下命令

./scripts/noIntegration.sh

要使用八个核心,请运行以下命令

CORES=8 ./scripts/noIntegration.sh

要生成文档(包括根项目和 Maven 插件的文档),请运行以下命令

./scripts/generateDocs.sh