create gradle tasks "test", "testSql", "migrations" and run docker before tasks
This commit is contained in:
203
build.gradle.kts
203
build.gradle.kts
@@ -3,13 +3,17 @@ import io.gitlab.arturbosch.detekt.Detekt
|
||||
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
|
||||
import org.owasp.dependencycheck.reporting.ReportGenerator
|
||||
import org.slf4j.LoggerFactory
|
||||
import fr.postgresjson.connexion.Connection
|
||||
import fr.postgresjson.migration.Migrations
|
||||
import com.typesafe.config.ConfigFactory
|
||||
import fr.postgresjson.connexion.Requester
|
||||
|
||||
val ktor_version: String by project
|
||||
val kotlin_version: String by project
|
||||
val coroutinesVersion: String by project
|
||||
val logback_version: String by project
|
||||
val koinVersion: String by project
|
||||
val jackson_version: String by project
|
||||
val ktorVersion = "1.5.0"
|
||||
val kotlinVersion = "1.4.30"
|
||||
val coroutinesVersion = "1.4.2"
|
||||
val logbackVersion = "1.2.3"
|
||||
val koinVersion = "2.0.1"
|
||||
val jacksonVersion = "2.12.1"
|
||||
|
||||
group = "com.github.flecomte"
|
||||
version = versioning.info.run {
|
||||
@@ -36,17 +40,121 @@ plugins {
|
||||
id("net.nemerosa.versioning") version "2.14.0"
|
||||
id("io.gitlab.arturbosch.detekt") version "1.16.0-RC1"
|
||||
id("info.solidsoft.pitest") version "1.5.2"
|
||||
id("com.avast.gradle.docker-compose") version "0.14.0"
|
||||
}
|
||||
|
||||
application {
|
||||
mainClassName = "io.ktor.server.jetty.EngineMain"
|
||||
}
|
||||
|
||||
buildscript {
|
||||
repositories {
|
||||
mavenLocal()
|
||||
mavenCentral()
|
||||
jcenter()
|
||||
maven { url = uri("https://jitpack.io") }
|
||||
}
|
||||
dependencies {
|
||||
classpath("com.typesafe:config:1.4.1")
|
||||
classpath("com.github.flecomte:postgres-json:2.1.1")
|
||||
}
|
||||
}
|
||||
|
||||
tasks.withType<KotlinCompile> {
|
||||
kotlinOptions {
|
||||
jvmTarget = "11"
|
||||
}
|
||||
}
|
||||
|
||||
val migration by tasks.registering {
|
||||
group = "application"
|
||||
dependsOn(tasks.named("composeUp"))
|
||||
|
||||
doLast {
|
||||
val config = ConfigFactory.parseFile(file("${buildDir}/../src/main/resources/application.conf")).resolve()
|
||||
val connection = Connection(
|
||||
host = config.getString("db.host"),
|
||||
port = config.getInt("db.port"),
|
||||
database = config.getString("db.database"),
|
||||
username = config.getString("db.username"),
|
||||
password = config.getString("db.password")
|
||||
)
|
||||
Migrations(
|
||||
connection,
|
||||
file("$buildDir/../src/main/resources/sql/migrations").toURI(),
|
||||
file("$buildDir/../src/main/resources/sql/functions").toURI()
|
||||
).run {
|
||||
run()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
val migrationTest by tasks.registering {
|
||||
group = "verification"
|
||||
dependsOn(tasks.named("testComposeUp"))
|
||||
finalizedBy(tasks.named("testComposeDown"))
|
||||
doLast {
|
||||
val config = ConfigFactory.parseFile(file("${buildDir}/../src/test/resources/application-test.conf")).resolve()
|
||||
val connection = Connection(
|
||||
host = config.getString("db.host"),
|
||||
port = config.getInt("db.port"),
|
||||
database = config.getString("db.database"),
|
||||
username = config.getString("db.username"),
|
||||
password = config.getString("db.password")
|
||||
)
|
||||
Migrations(
|
||||
connection,
|
||||
file("$buildDir/../src/main/resources/sql/migrations").toURI(),
|
||||
file("$buildDir/../src/main/resources/sql/functions").toURI()
|
||||
).run {
|
||||
run()
|
||||
connection.disconnect()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
val testSql by tasks.registering {
|
||||
group = "verification"
|
||||
dependsOn(tasks.named("testComposeUp"))
|
||||
finalizedBy(tasks.named("testComposeDown"))
|
||||
|
||||
doLast {
|
||||
val config = ConfigFactory.parseFile(file("${buildDir}/../src/test/resources/application-test.conf")).resolve()
|
||||
|
||||
val connection = Connection(
|
||||
host = config.getString("db.host"),
|
||||
port = config.getInt("db.port"),
|
||||
database = config.getString("db.database"),
|
||||
username = config.getString("db.username"),
|
||||
password = config.getString("db.password")
|
||||
)
|
||||
|
||||
Migrations(
|
||||
connection,
|
||||
file("$buildDir/../src/main/resources/sql/migrations").toURI(),
|
||||
file("$buildDir/../src/main/resources/sql/functions").toURI(),
|
||||
file("$buildDir/../src/test/sql/fixtures").toURI()
|
||||
).run {
|
||||
run()
|
||||
}
|
||||
|
||||
Requester.RequesterFactory(
|
||||
connection = connection,
|
||||
queriesDirectory = file("${buildDir}/../src/test/sql").toURI()
|
||||
).createRequester().run {
|
||||
getQueries().map {
|
||||
try {
|
||||
it.sendQuery() == 0
|
||||
} catch (e: Exception) {
|
||||
false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
connection.disconnect()
|
||||
}
|
||||
}
|
||||
|
||||
tasks.withType<Jar> {
|
||||
manifest {
|
||||
attributes(
|
||||
@@ -57,23 +165,48 @@ tasks.withType<Jar> {
|
||||
}
|
||||
}
|
||||
|
||||
tasks {
|
||||
named<ShadowJar>("shadowJar") {
|
||||
mergeServiceFiles("META-INF/services")
|
||||
archiveFileName.set("${archiveBaseName.get()}-latest-all.${archiveExtension.get()}")
|
||||
}
|
||||
tasks.named<ShadowJar>("shadowJar") {
|
||||
mergeServiceFiles("META-INF/services")
|
||||
archiveFileName.set("${archiveBaseName.get()}-latest-all.${archiveExtension.get()}")
|
||||
}
|
||||
|
||||
val sourcesJar by tasks.creating(Jar::class) {
|
||||
tasks.sonarqube.configure { dependsOn(tasks.jacocoTestReport) }
|
||||
|
||||
val sourcesJar by tasks.registering(Jar::class) {
|
||||
group = "build"
|
||||
archiveClassifier.set("sources")
|
||||
from(sourceSets.getByName("main").allSource)
|
||||
}
|
||||
|
||||
tasks.test {
|
||||
useJUnit()
|
||||
useJUnitPlatform()
|
||||
systemProperty("junit.jupiter.execution.parallel.enabled", true)
|
||||
dependsOn(testSql)
|
||||
dependsOn(tasks.pitest)
|
||||
finalizedBy(tasks.jacocoTestReport) // report is always generated after tests run
|
||||
// maxHeapSize = "1G"
|
||||
}
|
||||
|
||||
apply(plugin = "docker-compose")
|
||||
dockerCompose {
|
||||
projectName = "dc-project"
|
||||
useComposeFiles = listOf("docker-compose.yml")
|
||||
startedServices = listOf("db", "elasticsearch", "rabbitmq", "redis")
|
||||
stopContainers = false
|
||||
isRequiredBy(project.tasks.run)
|
||||
createNested("test").apply {
|
||||
projectName = "dc-project_test"
|
||||
useComposeFiles = listOf("docker-compose-test.yml")
|
||||
stopContainers = false
|
||||
isRequiredBy(project.tasks.test)
|
||||
isRequiredBy(project.tasks.named("testSql"))
|
||||
}
|
||||
createNested("sonarqube").apply {
|
||||
projectName = "dc-project"
|
||||
useComposeFiles = listOf("docker-compose-sonar.yml")
|
||||
stopContainers = false
|
||||
// isRequiredBy(project.tasks.sonarqube)
|
||||
}
|
||||
}
|
||||
|
||||
publishing {
|
||||
@@ -106,10 +239,12 @@ jacoco {
|
||||
toolVersion = "0.8.6"
|
||||
applyTo(tasks.run.get())
|
||||
}
|
||||
|
||||
tasks.register<JacocoReport>("applicationCodeCoverageReport") {
|
||||
executionData(tasks.run.get())
|
||||
sourceSets(sourceSets.main.get())
|
||||
}
|
||||
|
||||
tasks.jacocoTestReport {
|
||||
dependsOn(tasks.test)
|
||||
reports {
|
||||
@@ -159,43 +294,45 @@ repositories {
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version")
|
||||
implementation(gradleApi())
|
||||
implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlinVersion")
|
||||
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:$coroutinesVersion")
|
||||
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-reactor:$coroutinesVersion")
|
||||
implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.0.1")
|
||||
implementation("io.ktor:ktor-server-jetty:$ktor_version")
|
||||
implementation("io.ktor:ktor-client-jetty:$ktor_version")
|
||||
implementation("ch.qos.logback:logback-classic:$logback_version")
|
||||
implementation("io.ktor:ktor-server-core:$ktor_version")
|
||||
implementation("io.ktor:ktor-locations:$ktor_version")
|
||||
implementation("io.ktor:ktor-auth:$ktor_version")
|
||||
implementation("io.ktor:ktor-auth-jwt:$ktor_version")
|
||||
implementation("io.ktor:ktor-websockets:$ktor_version")
|
||||
implementation("io.ktor:ktor-server-jetty:$ktorVersion")
|
||||
implementation("io.ktor:ktor-client-jetty:$ktorVersion")
|
||||
implementation("ch.qos.logback:logback-classic:$logbackVersion")
|
||||
implementation("io.ktor:ktor-server-core:$ktorVersion")
|
||||
implementation("io.ktor:ktor-locations:$ktorVersion")
|
||||
implementation("io.ktor:ktor-auth:$ktorVersion")
|
||||
implementation("io.ktor:ktor-auth-jwt:$ktorVersion")
|
||||
implementation("io.ktor:ktor-websockets:$ktorVersion")
|
||||
implementation("org.koin:koin-ktor:$koinVersion")
|
||||
implementation("io.ktor:ktor-jackson:$ktor_version")
|
||||
implementation("com.fasterxml.jackson.module:jackson-module-kotlin:$jackson_version")
|
||||
implementation("com.fasterxml.jackson.datatype:jackson-datatype-joda:$jackson_version")
|
||||
implementation("io.ktor:ktor-jackson:$ktorVersion")
|
||||
implementation("com.fasterxml.jackson.module:jackson-module-kotlin:$jacksonVersion")
|
||||
implementation("com.fasterxml.jackson.datatype:jackson-datatype-joda:$jacksonVersion")
|
||||
implementation("net.pearx.kasechange:kasechange-jvm:1.3.0")
|
||||
implementation("com.auth0:java-jwt:3.12.0")
|
||||
implementation("com.github.jasync-sql:jasync-postgresql:1.1.6")
|
||||
implementation("com.github.flecomte:postgres-json:2.0.0")
|
||||
implementation("com.github.flecomte:postgres-json:2.1.1")
|
||||
implementation("com.sendgrid:sendgrid-java:4.7.1")
|
||||
implementation("io.lettuce:lettuce-core:5.3.6.RELEASE") // TODO update to 6.0.2
|
||||
implementation("com.rabbitmq:amqp-client:5.10.0")
|
||||
implementation("org.elasticsearch.client:elasticsearch-rest-client:6.7.1")
|
||||
implementation("com.jayway.jsonpath:json-path:2.5.0")
|
||||
implementation("com.avast.gradle:gradle-docker-compose-plugin:0.14.0")
|
||||
|
||||
testImplementation("io.ktor:ktor-server-tests:$ktor_version")
|
||||
testImplementation("io.ktor:ktor-client-mock:$ktor_version")
|
||||
testImplementation("io.ktor:ktor-client-mock-jvm:$ktor_version")
|
||||
testImplementation("io.ktor:ktor-server-tests:$ktorVersion")
|
||||
testImplementation("io.ktor:ktor-client-mock:$ktorVersion")
|
||||
testImplementation("io.ktor:ktor-client-mock-jvm:$ktorVersion")
|
||||
testImplementation("org.koin:koin-test:$koinVersion")
|
||||
testImplementation("org.jetbrains.kotlinx:kotlinx-coroutines-test:$coroutinesVersion")
|
||||
testImplementation("io.mockk:mockk:1.10.5")
|
||||
testImplementation("io.mockk:mockk:1.10.6")
|
||||
testImplementation("org.junit.jupiter:junit-jupiter:5.7.0")
|
||||
testImplementation("org.amshove.kluent:kluent:1.61")
|
||||
pitest("org.pitest:pitest-junit5-plugin:0.5")
|
||||
testImplementation("io.mockk:mockk-agent-api:1.10.5")
|
||||
testImplementation("io.mockk:mockk-agent-jvm:1.10.5")
|
||||
testImplementation("org.jetbrains.kotlin:kotlin-reflect:$kotlin_version")
|
||||
testImplementation("io.mockk:mockk-agent-api:1.10.6")
|
||||
testImplementation("io.mockk:mockk-agent-jvm:1.10.6")
|
||||
testImplementation("org.jetbrains.kotlin:kotlin-reflect:$kotlinVersion")
|
||||
testImplementation("com.thedeanda:lorem:2.1")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user