== How to Build Spring Cloud Contract

=== Cloning the repository on Windows

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.

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

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):


[source,bash]
----
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):

[source,bash]
----
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):

[source,bash]
----
git clone -c core.longPaths=true https://github.com/spring-cloud/spring-cloud-contract.git
----

IMPORTANT: 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.

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

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

=== Project structure

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`: Folder contains setup for Spring Cloud Release Tools automated release process
- `docker`: Folder contains docker images
- `samples`: Folder contains test samples together with standalone ones used also to build documentation
- `scripts`: Contains scripts to build and test `Spring Cloud Contract` with Maven, Gradle and standalone projects
- `specs`: Contains specifications for the Contract DSL.
- `spring-cloud-contract-dependencies`: Contains Spring Cloud Contract BOM
- `spring-cloud-contract-shade`: Shaded dependencies used by the plugins
- `spring-cloud-contract-starters`: Contains Spring Cloud Contract Starters
- `spring-cloud-contract-spec`: Contains specification modules (contains concept of a Contract)
- `spring-cloud-contract-stub-runner`: Contains Stub Runner related modules
- `spring-cloud-contract-stub-runner-boot`: Contains Stub Runner Boot app
- `spring-cloud-contract-tools`: Gradle and Maven plugin for `Spring Cloud Contract Verifier`
- `spring-cloud-contract-verifier`: Core of the `Spring Cloud Contract Verifier` functionality
- `spring-cloud-contract-wiremock`: All WireMock related functionality
- `tests`: Integration tests for different messaging technologies

=== Commands

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

```
./mvnw clean install -P integration
```

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).

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
```

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
```

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

```
./scripts/generateDocs.sh
```
