import org.springframework.util.SocketUtils.findAvailableTcpPort
plugins {
id("org.springframework.boot") version "2.5.4"
id("io.spring.dependency-management") version "1.0.11.RELEASE"
kotlin("jvm") version "1.5.21"
kotlin("plugin.spring") version "1.5.21"
jacoco
}
group = "au.com.hoa.demo"
version = "1.0"
java.sourceCompatibility = JavaVersion.VERSION_11
val jdkVersion = "11"
val gradleVersion = "7.1.1"
val jacocoRate = 0.75
val ktlint: Configuration by configurations.creating
val codeCoverageExclusions: Array<String> = arrayOf(
"au/com/hoa/demo/customer/NananaKt*"
)
repositories {
maven(url = "https://maven.nexus3.hoa...")
}
dependencies {
val springCloudVersion = "2020.0.3"
val kotlinLoggingVersion = "2.0.10"
val problemVersion = "0.26.2"
val logstashVersion = "6.6"
val reactorKotlinExtensionVersion = "1.1.3"
val oktaVersion = "0.4.0"
val jjwtVersion = "0.11.2"
// TEST
val jupiterVersion = "5.7.2"
val mockkVersion = "1.12.0"
val springMockkVersion = "1.1.0"
val kluentVersion = "1.68"
val kotlinJsonAssertionVersion = "0.1.0"
val restAssuredVersion = "4.2.0"
val swaggerRequestValidatorVersion = "2.9.0"
val wireMockVersion = "2.27.2"
val reactorTestVersion = "3.4.8"
implementation(platform("org.springframework.cloud:spring-cloud-dependencies:$springCloudVersion"))
implementation("org.jetbrains.kotlin:kotlin-reflect")
implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8")
implementation("org.springframework.boot:spring-boot-starter-webflux")
implementation("org.springframework.boot:spring-boot-starter-actuator")
implementation("org.springframework.boot:spring-boot-starter-cache")
implementation("org.springframework.cloud:spring-cloud-starter-sleuth")
implementation("org.springframework.boot:spring-boot-starter-security")
implementation("org.springframework.security:spring-security-oauth2-resource-server")
implementation("org.springframework.security:spring-security-oauth2-jose")
implementation("org.springframework.boot:spring-boot-starter-mustache")
implementation("org.zalando:problem-spring-webflux:$problemVersion")
implementation("net.logstash.logback:logstash-logback-encoder:$logstashVersion")
implementation("io.github.microutils:kotlin-logging:$kotlinLoggingVersion")
implementation("io.projectreactor.kotlin:reactor-kotlin-extensions:$reactorKotlinExtensionVersion")
implementation("com.fasterxml.jackson.module:jackson-module-kotlin")
implementation("com.okta.jwt:okta-jwt-verifier:$oktaVersion")
implementation("com.okta.jwt:okta-jwt-verifier-impl:$oktaVersion")
implementation("io.jsonwebtoken:jjwt-api:$jjwtVersion")
runtimeOnly("io.jsonwebtoken:jjwt-impl:$jjwtVersion")
runtimeOnly("io.jsonwebtoken:jjwt-jackson:$jjwtVersion")
testImplementation("org.springframework.boot:spring-boot-starter-test")
testImplementation("org.mockito:mockito-junit-jupiter")
testImplementation("org.junit.jupiter:junit-jupiter:$jupiterVersion")
testImplementation("org.amshove.kluent:kluent:$kluentVersion")
testImplementation("io.mockk:mockk:$mockkVersion")
testImplementation("io.projectreactor:reactor-test:$reactorTestVersion")
testImplementation("io.rest-assured:rest-assured:$restAssuredVersion")
testImplementation("io.rest-assured:json-path:$restAssuredVersion")
testImplementation("io.rest-assured:xml-path:$restAssuredVersion")
testImplementation("io.rest-assured:rest-assured-common:$restAssuredVersion")
testImplementation("io.rest-assured:kotlin-extensions:$restAssuredVersion")
testImplementation("com.ninja-squad:springmockk:$springMockkVersion")
testImplementation("com.gregwoodfill.assert:kotlin-json-assert:$kotlinJsonAssertionVersion")
testImplementation("com.atlassian.oai:swagger-request-validator-restassured:$swaggerRequestValidatorVersion")
testImplementation("com.github.tomakehurst:wiremock-standalone:$wireMockVersion")
ktlint("com.pinterest:ktlint:0.42.0")
}
tasks {
compileKotlin {
kotlinOptions {
freeCompilerArgs = listOf("-Xjsr305=strict")
jvmTarget = jdkVersion
}
}
compileTestKotlin {
kotlinOptions.jvmTarget = jdkVersion
}
wrapper {
distributionUrl = "https://services.gradle.org/distributions/gradle-$gradleVersion-all.zip"
}
bootJar {
archiveFileName.set("app.jar")
}
test {
environment("wiremock.random_port", findAvailableTcpPort())
useJUnitPlatform()
finalizedBy(jacocoTestReport)
}
check {
dependsOn("ktlint")
dependsOn(jacocoTestCoverageVerification)
}
jacocoTestCoverageVerification {
val excludedPackages = classDirectories.files.map {
fileTree(it).apply {
exclude(*codeCoverageExclusions)
}
}
classDirectories.setFrom(files(excludedPackages))
violationRules {
rule {
limit {
minimum = BigDecimal(jacocoRate)
}
}
}
}
jacocoTestReport {
classDirectories.setFrom(
sourceSets.main.get().output.asFileTree.matching {
exclude(*codeCoverageExclusions)
}
)
dependsOn("test")
reports {
html.required.set(true)
xml.required.set(true)
}
}
create<JavaExec>("ktlint") {
group = "verification"
description = "Check Kotlin code style."
classpath = configurations["ktlint"]
mainClass.set("com.pinterest.ktlint.Main")
args("src/**/*.kt", "--verbose")
}
bootRun {
jvmArgs("-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=*:5005")
}
}
jacoco {
toolVersion = "0.8.7"
reportsDirectory.set(layout.buildDirectory.dir("reports/jacoco"))
}