* Upgrade gradle wrapper to 6.4. Fixes gh-1387. * Document PublishStubsToScmTask API changes. * Upgrade groovy to 2.5.10.
161 lines
4.9 KiB
Groovy
161 lines
4.9 KiB
Groovy
buildscript {
|
|
repositories {
|
|
mavenLocal()
|
|
mavenCentral()
|
|
if (!"${verifierVersion}".contains("RELEASE")) {
|
|
maven { url "https://repo.spring.io/snapshot" }
|
|
maven { url "https://repo.spring.io/milestone" }
|
|
maven { url "https://repo.spring.io/release" }
|
|
}
|
|
}
|
|
|
|
dependencies {
|
|
classpath "io.spring.gradle:dependency-management-plugin:1.0.8.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 "https://repo.spring.io/snapshot" }
|
|
maven { url "https://repo.spring.io/milestone" }
|
|
maven { url "https://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 {
|
|
testImplementation("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"
|
|
stubsSuffix = getProp("PRODUCER_STUBS_CLASSIFIER") ?: "stubs"
|
|
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) {
|
|
contractRepository {
|
|
repositoryUrl = getProp('EXTERNAL_CONTRACTS_REPO_WITH_BINARIES_URL') ?:
|
|
getProp('REPO_WITH_BINARIES_URL') ?: 'http://localhost:8081/artifactory/libs-release-local'
|
|
username = getProp('EXTERNAL_CONTRACTS_REPO_WITH_BINARIES_USERNAME') ?:
|
|
getProp('REPO_WITH_BINARIES_USERNAME') ?: 'admin'
|
|
password = getProp('EXTERNAL_CONTRACTS_REPO_WITH_BINARIES_PASSWORD') ?:
|
|
getProp('REPO_WITH_BINARIES_PASSWORD') ?: 'password'
|
|
}
|
|
}
|
|
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") ?: "+"
|
|
}
|
|
contractsMode = Boolean.
|
|
parseBoolean(getProp("EXTERNAL_CONTRACTS_WORK_OFFLINE")) ? "LOCAL" : "REMOTE"
|
|
}
|
|
else {
|
|
logger.lifecycle("Will use contracts from the mounted [/contracts] folder")
|
|
// tests - contracts in this repo
|
|
contractsDslDir = new File("/contracts")
|
|
}
|
|
}
|
|
|
|
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 {
|
|
}
|
|
}
|
|
|
|
// explicitly disable artifacts publication
|
|
boolean publishEnabled = Boolean.parseBoolean(getProp("PUBLISH_ARTIFACTS") ?: "true")
|
|
boolean publishOffline = Boolean.parseBoolean(getProp("PUBLISH_ARTIFACTS_OFFLINE") ?: "false")
|
|
publish.setEnabled(publishEnabled)
|
|
publishToMavenLocal.setEnabled(publishOffline)
|
|
|
|
gradle.taskGraph.whenReady { graph ->
|
|
graph.allTasks.
|
|
findAll { it.name.startsWith("publish") && "publishStubsToScm" != it.name }*.
|
|
setEnabled(publishEnabled)
|
|
graph.allTasks.
|
|
findAll { it.name.startsWith("publish") && it.name.endsWith("ToMavenLocal") }*.setEnabled(publishOffline)
|
|
}
|
|
|
|
if (Boolean.parseBoolean(getProp("PUBLISH_STUBS_TO_SCM"))) {
|
|
publish.dependsOn("publishStubsToScm")
|
|
}
|
|
|
|
String getProp(String propName) {
|
|
return hasProperty(propName) ?
|
|
(getProperty(propName) ?: System.properties[propName]) : System.properties[propName] ?:
|
|
System.getenv(propName)
|
|
}
|
|
|
|
task resolveDependencies {
|
|
description "Pre-downloads *most* dependencies"
|
|
doLast {
|
|
configurations.getAsMap().each { name, config ->
|
|
println "Retrieving dependencies for $name"
|
|
try {
|
|
config.files
|
|
} catch (e) {
|
|
project.logger.info e.message // some cannot be resolved, silentlyish skip them
|
|
}
|
|
}
|
|
}
|
|
}
|