如何構建 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: 包含 Contract DSL 的規範。

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

  • spring-cloud-contract-shade: 外掛使用的 shaded 依賴項

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

  • spring-cloud-contract-spec: 包含規範模組(包含 Contract 的概念)

  • 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
© . This site is unofficial and not affiliated with VMware.