These environment variables are used when contracts lay in an external repository. To enable this feature you must set the `EXTERNAL_CONTRACTS_ARTIFACT_ID` environment variable. - `EXTERNAL_CONTRACTS_GROUP_ID` - group id of the project with contracts. Defaults to `com.example` - `EXTERNAL_CONTRACTS_ARTIFACT_ID`- artifact id of the project with contracts. - `EXTERNAL_CONTRACTS_CLASSIFIER`- classifier of the project with contracts. Empty by default - `EXTERNAL_CONTRACTS_VERSION` - version of the project with contracts. Defaults to `+`, equivalent to picking the latest - `EXTERNAL_CONTRACTS_REPO_WITH_BINARIES_URL` - URL of your Artifact Manager. Defaults to value of `REPO_WITH_BINARIES_URL` env var. If that's not set, defaults to `http://localhost:8081/artifactory/libs-release-local` which is the default URL of https://jfrog.com/artifactory/[Artifactory] running locally - `EXTERNAL_CONTRACTS_PATH` - path to contracts for the given project, inside the project with contracts. Defaults to slash separated `EXTERNAL_CONTRACTS_GROUP_ID` concatenated with `/` and `EXTERNAL_CONTRACTS_ARTIFACT_ID`. E.g. for group id `foo.bar` and artifact id `baz`, would result in `foo/bar/baz` contracts path. - `EXTERNAL_CONTRACTS_WORK_OFFLINE` - if set to `true` then will retrieve artifact with contracts from the container's `.m2`. Mount your local `.m2` as a volume available at the container's `/root/.m2` path. You must not set both `EXTERNAL_CONTRACTS_WORK_OFFLINE` and `EXTERNAL_CONTRACTS_REPO_WITH_BINARIES_URL`. fixes gh-576
135 lines
4.0 KiB
Groovy
135 lines
4.0 KiB
Groovy
buildscript {
|
|
repositories {
|
|
mavenLocal()
|
|
mavenCentral()
|
|
if (!"${verifierVersion}".contains("RELEASE")) {
|
|
maven { url "http://repo.spring.io/snapshot" }
|
|
maven { url "http://repo.spring.io/milestone" }
|
|
maven { url "http://repo.spring.io/release" }
|
|
}
|
|
}
|
|
|
|
dependencies {
|
|
classpath "io.spring.gradle:dependency-management-plugin:1.0.4.RELEASE"
|
|
classpath "org.springframework.cloud:spring-cloud-contract-gradle-plugin:${verifierVersion}"
|
|
}
|
|
}
|
|
|
|
group = getProp("PROJECT_GROUP") ?: 'com.example'
|
|
version = getProp("PROJECT_VERSION") ?: '0.0.1-SNAPSHOT'
|
|
|
|
repositories {
|
|
mavenLocal()
|
|
mavenCentral()
|
|
if (!"${verifierVersion}".contains("RELEASE")) {
|
|
maven { url "http://repo.spring.io/snapshot" }
|
|
maven { url "http://repo.spring.io/milestone" }
|
|
maven { url "http://repo.spring.io/release" }
|
|
}
|
|
}
|
|
|
|
apply plugin: 'groovy'
|
|
apply plugin: 'io.spring.dependency-management'
|
|
apply plugin: 'spring-cloud-contract'
|
|
apply plugin: 'maven-publish'
|
|
|
|
dependencyManagement {
|
|
imports {
|
|
mavenBom "org.springframework.cloud:spring-cloud-contract-dependencies:${verifierVersion}"
|
|
}
|
|
}
|
|
|
|
dependencies {
|
|
testCompile("org.springframework.cloud:spring-cloud-starter-contract-verifier")
|
|
}
|
|
|
|
test {
|
|
testLogging {
|
|
exceptionFormat = 'full'
|
|
afterSuite { desc, result ->
|
|
if (!desc.parent) {
|
|
println "Results: (${result.testCount} tests, ${result.successfulTestCount} successes, ${result.failedTestCount} failures, ${result.skippedTestCount} skipped)"
|
|
if (result.testCount == 0) {
|
|
throw new IllegalStateException("No tests were found. Failing the build")
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
contracts {
|
|
baseClassForTests = "contracts.RestBase"
|
|
testMode = "EXPLICIT"
|
|
if (getProp("EXTERNAL_CONTRACTS_ARTIFACT_ID")) {
|
|
logger.lifecycle("Will use an artifact with contracts [${getProp("EXTERNAL_CONTRACTS_GROUP_ID")}:${getProp("EXTERNAL_CONTRACTS_ARTIFACT_ID")}]")
|
|
// tests - contracts from an artifact
|
|
contractsPath = getProp("EXTERNAL_CONTRACTS_PATH") ?: ""
|
|
if (Boolean.parseBoolean(getProp("EXTERNAL_CONTRACTS_WORK_OFFLINE")) == false) {
|
|
contractsRepositoryUrl = getProp('EXTERNAL_CONTRACTS_REPO_WITH_BINARIES_URL') ?:
|
|
getProp('REPO_WITH_BINARIES_URL') ?: 'http://localhost:8081/artifactory/libs-release-local'
|
|
}
|
|
contractDependency {
|
|
groupId = getProp("EXTERNAL_CONTRACTS_GROUP_ID") ?: "com.example"
|
|
artifactId = getProp("EXTERNAL_CONTRACTS_ARTIFACT_ID")
|
|
delegate.classifier = getProp("EXTERNAL_CONTRACTS_CLASSIFIER") ?: ""
|
|
delegate.version = getProp("EXTERNAL_CONTRACTS_VERSION") ?: "+"
|
|
}
|
|
contractsWorkOffline = Boolean.parseBoolean(getProp("EXTERNAL_CONTRACTS_WORK_OFFLINE")) ?: false
|
|
} else {
|
|
logger.lifecycle("Will use contracts from the mounted [/contracts] folder")
|
|
// tests - contracts in this repo
|
|
contractsDslDir = new File("/contracts")
|
|
}
|
|
}
|
|
|
|
task wrapper(type: Wrapper) {
|
|
gradleVersion = '4.4.1'
|
|
}
|
|
|
|
task cleanOutput(type: Delete) {
|
|
def dirName = "/spring-cloud-contract-output"
|
|
file(dirName).list().each {
|
|
f -> delete "${dirName}/${f}"
|
|
}
|
|
}
|
|
|
|
task copyOutput(type: Copy) {
|
|
dependsOn("cleanOutput")
|
|
from 'build'
|
|
into '/spring-cloud-contract-output'
|
|
}
|
|
|
|
test.finalizedBy("copyOutput")
|
|
|
|
publishing {
|
|
repositories {
|
|
maven {
|
|
url getProp('REPO_WITH_BINARIES_URL') ?: 'http://localhost:8081/artifactory/libs-release-local'
|
|
credentials {
|
|
username getProp('REPO_WITH_BINARIES_USERNAME') ?: 'admin'
|
|
password getProp('REPO_WITH_BINARIES_PASSWORD') ?: 'password'
|
|
}
|
|
}
|
|
}
|
|
publications {
|
|
mavenJava(MavenPublication) {
|
|
from components.java
|
|
}
|
|
}
|
|
}
|
|
|
|
// explicitly disable artifacts publication
|
|
String publishArtifacts = getProp("PUBLISH_ARTIFACTS") ?: "true"
|
|
boolean publishEnabled = Boolean.parseBoolean(publishArtifacts)
|
|
publish.setEnabled(publishEnabled)
|
|
|
|
gradle.taskGraph.whenReady { graph ->
|
|
graph.allTasks.findAll { it.name.startsWith("publish") }*.setEnabled(publishEnabled)
|
|
}
|
|
|
|
String getProp(String propName) {
|
|
return hasProperty(propName) ?
|
|
(getProperty(propName) ?: System.properties[propName]) : System.properties[propName] ?:
|
|
System.getenv(propName)
|
|
}
|