How to Build Spring Cloud Contract

Cloning the repository on Windows

在 Windows 上克隆此项目时,git 存储库中的一些文件可能会超过 Windows 255 个字符的最大文件路径限制,这可能会导致存储库签出不正确(可能部分签出)。

While cloning this project on Windows, some files in the git repository may exceed the Windows maximum file path limit of 255 characters, which may result in an incorrectly (probably partially) checked out repository.

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

To resolve this issue, you can set the core.longPaths attribute to true or clone the Spring Cloud Contract repository.

若要将 core.longPaths 属性设置为 true,您有三个选项:

To set the core.longPaths attribute to true, you have three options:

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

  • Change it for all users of the machine (doing so requires administrator privileges):

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

  • Change it for the current user (no administrative privileges required):

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

  • Change for just this repository (administrative privileges depend on where the repository is being cloned to):

git clone -c core.longPaths=true https://github.com/spring-cloud/spring-cloud-contract.git

您需要安装所有必需的 Groovy 插件,以便您的 IDE 正确解析源。例如,在 Intellij IDEA 中,同时安装 Eclipse Groovy 编译器插件和 GMavenPlus Intellij 插件会导致正确导入项目。

You need to have all the necessary Groovy plugins installed for your IDE to properly resolve the sources. For example, in Intellij IDEA, having both the Eclipse Groovy Compiler Plugin and the GMavenPlus Intellij Plugin results in properly imported project.

Spring Cloud Contract 构建 Docker 镜像。请记住安装 Docker。

Spring Cloud Contract builds Docker images. Remember to have Docker installed.

如果您想在脱机模式下运行构建,则必须安装 Maven 3.5.2+。

If you want to run the build in offline mode, you must have Maven 3.5.2+ installed.

Project structure

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

The following listing shows the Spring Cloud Contract folder structure:

├── 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

下面的清单说明了项目结构中每个顶级文件夹:

The following list describes each of the top-level folders in the project structure:

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

  • config: Folder contains setup for Spring Cloud Release Tools automated release process

  • docker:文件夹包含Docker镜像

  • docker: Folder contains docker images

  • samples:文件夹包含测试样本以及用于构建文档的独立样本

  • samples: Folder contains test samples together with standalone ones used also to build documentation

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

  • scripts: Contains scripts to build and test Spring Cloud Contract with Maven, Gradle and standalone projects

  • specs:包含Contract DSL的规范。

  • specs: Contains specifications for the Contract DSL.

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

  • spring-cloud-contract-dependencies: Contains Spring Cloud Contract BOM

  • spring-cloud-contract-shade: 插件使用着色的依赖项

  • spring-cloud-contract-shade: Shaded dependencies used by the plugins

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

  • spring-cloud-contract-starters: Contains Spring Cloud Contract Starters

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

  • spring-cloud-contract-spec: Contains specification modules (contains concept of a Contract)

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

  • spring-cloud-contract-stub-runner: Contains Stub Runner related modules

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

  • spring-cloud-contract-stub-runner-boot: Contains Stub Runner Boot app

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

  • spring-cloud-contract-tools: Gradle and Maven plugin for Spring Cloud Contract Verifier

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

  • spring-cloud-contract-verifier: Core of the Spring Cloud Contract Verifier functionality

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

  • spring-cloud-contract-wiremock: All WireMock related functionality

  • tests: 针对不同消息传递技术进行集成测试

  • tests: Integration tests for different messaging technologies

Commands

要连同 Maven 插件一起构建核心功能,您可以运行以下命令:

To build the core functionality together with the Maven Plugin, you can run the following command:

./mvnw clean install -P integration

调用该函数会构建核心、Maven 插件和 Gradle 插件,并按正确顺序对独立样本运行端到端测试(适用于 Maven 和 Gradle)。

Calling that function builds the core, the Maven plugin, and the Gradle plugin and runs end-to_end tests on the standalone samples in the proper order (both for Maven and Gradle).

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

To build only the Gradle Plugin, you can run the following commands:

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

Helpful scripts

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

We provide a couple of helpful scripts to build the project.

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

To build the project in parallel (by default, it uses four cores, but you can change it), run the following command:

./scripts/parallelBuild.sh

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

To use eight 8 cores, run the following command:

CORES=8 ./scripts/parallelBuild.sh

要在不进行任何集成测试的情况下构建项目(默认情况下,这会使用一个核心),请运行以下命令:

To build the project without any integration tests (by default, this uses one core), run the following command:

./scripts/noIntegration.sh

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

To use eight cores, run the following command:

CORES=8 ./scripts/noIntegration.sh

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

To generate the documentation (for both the root project and the maven plugin), run the following command:

./scripts/generateDocs.sh