Files
spring-cloud-contract/samples/standalone/restdocs/http-server/build.gradle
2023-12-14 11:15:16 +01:00

129 lines
3.5 KiB
Groovy

plugins {
id "groovy"
id "org.springframework.boot"
id "io.spring.dependency-management"
id "org.springframework.cloud.contract"
id "maven-publish"
}
group = 'com.example'
version = '0.0.1'
repositories {
mavenCentral()
mavenLocal()
maven { url "https://repo.spring.io/snapshot" }
maven { url "https://repo.spring.io/milestone" }
}
dependencyManagement {
imports {
mavenBom "org.springframework.cloud:spring-cloud-contract-dependencies:${verifierVersion}"
}
}
dependencies {
implementation("org.springframework.boot:spring-boot-starter-web")
implementation("org.springframework.boot:spring-boot-starter-actuator")
implementation("com.fasterxml.jackson.dataformat:jackson-dataformat-xml")
testImplementation('org.springframework.boot:spring-boot-starter-test')
testImplementation 'org.springframework.cloud:spring-cloud-starter-contract-stub-runner'
// tag::dependencies[]
testImplementation 'org.springframework.cloud:spring-cloud-starter-contract-verifier'
testImplementation 'org.springframework.restdocs:spring-restdocs-mockmvc'
// end::dependencies[]
}
contracts {
baseClassMappings {
baseClassMapping('.*standalone.*', 'com.example.fraud.FraudBaseWithStandaloneSetup')
baseClassMapping('.*webapp.*', 'com.example.fraud.FraudBaseWithWebAppSetup')
}
}
generateClientStubs.enabled = false
test {
useJUnitPlatform()
systemProperty 'spring.profiles.active', 'gradle'
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")
}
}
}
}
task stubsJar(type: Jar, dependsOn: ['copySnippets', 'copySources', 'copyClasses']) {
archiveBaseName = project.name
archiveClassifier = 'stubs'
from project.file("${project.buildDir}/stubs")
}
task copySnippets(type: Copy, dependsOn: test) {
from "target/snippets/stubs"
into "${project.buildDir}/stubs/META-INF/${project.group}/${project.name}/${project.version}/mappings"
}
task copySources(type: Copy) {
from "src/main/java"
include '**/model/Fraud*.*'
into "${project.buildDir}/stubs/"
}
task copyClasses(type: Copy) {
from "${project.buildDir}/classes/main/"
include '**/model/Fraud*.*'
into "${project.buildDir}/stubs/"
}
project.tasks.named("verifierStubsJar").get().dependsOn('copySnippets', 'copySources', 'stubsJar') // TODO: We need to fix this
project.tasks.named("copyContracts").get().dependsOn('stubsJar') // TODO: We need to fix this
afterEvaluate {
project.tasks.matching { it.name.contains("publish") }.each { it.dependsOn('verifierStubsJar') } // TODO: We need to fix this
}
publishing {
publications {
maven(MavenPublication) {
artifact bootJar
artifact stubsJar
// https://github.com/spring-gradle-plugins/dependency-management-plugin/issues/273
versionMapping {
usage("java-api") {
fromResolutionOf("runtimeClasspath")
}
usage("java-runtime") {
fromResolutionResult()
}
}
}
}
}
clean.doFirst {
delete 'target/snippets/stubs'
delete "~/.m2/repository/com/example/http-server-restdocs-gradle"
}
task resolveDependencies {
doLast {
project.rootProject.allprojects.each { subProject ->
subProject.buildscript.configurations.each { configuration ->
configuration.resolve()
}
subProject.configurations.each { configuration ->
configuration.resolve()
}
}
}
}