Created
March 18, 2020 06:06
-
-
Save sandor-nemeth/c86bec565de2dc9ec54584eb99a97f8c to your computer and use it in GitHub Desktop.
Spring Boot / MongoDB / Reactive app boilerplate
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import org.gradle.api.tasks.testing.logging.TestExceptionFormat | |
import org.gradle.api.tasks.testing.logging.TestLogEvent | |
import org.gradle.plugins.ide.idea.model.IdeaLanguageLevel | |
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile | |
plugins { | |
val kotlinVersion = "1.3.61" | |
application | |
idea | |
kotlin("jvm") version kotlinVersion | |
kotlin("plugin.spring") version kotlinVersion | |
id("org.springframework.boot") version "2.2.2.RELEASE" | |
id("io.spring.dependency-management") version "1.0.8.RELEASE" | |
id("org.jlleitschuh.gradle.ktlint") version "9.2.1" | |
} | |
repositories { | |
mavenCentral() | |
} | |
val javaVer = JavaVersion.VERSION_11 | |
val kotlinLoggingVer = "1.7.8" | |
dependencies { | |
implementation(kotlin("stdlib-jdk8")) | |
implementation(kotlin("reflect")) | |
implementation("io.github.microutils:kotlin-logging:$kotlinLoggingVer") | |
implementation("com.fasterxml.jackson.module:jackson-module-kotlin") | |
implementation("org.springframework.boot:spring-boot-starter-webflux") | |
implementation("org.springframework.boot:spring-boot-starter-data-mongodb-reactive") | |
implementation("org.springframework.boot:spring-boot-starter-actuator") | |
// test dependencies | |
testImplementation("org.junit.jupiter:junit-jupiter:5.6.0") | |
testImplementation("org.springframework.boot:spring-boot-starter-test") { | |
exclude(group = "junit", module = "junit") | |
} | |
testImplementation("io.projectreactor:reactor-test") | |
testImplementation("de.flapdoodle.embed:de.flapdoodle.embed.mongo:2.2.0") | |
testImplementation("com.nhaarman.mockitokotlin2:mockito-kotlin:2.2.0") | |
} | |
val appName = "app" | |
val appVer by lazy { "0.0.1+${gitRev()}" } | |
group = "group" | |
version = appVer | |
application { | |
mainClassName = "package.App.kt" | |
applicationName = appName | |
} | |
java { | |
sourceCompatibility = javaVer | |
targetCompatibility = javaVer | |
} | |
idea { | |
project { | |
languageLevel = IdeaLanguageLevel(javaVer) | |
} | |
module { | |
isDownloadJavadoc = true | |
isDownloadSources = true | |
} | |
} | |
springBoot { | |
buildInfo { | |
properties { | |
artifact = "$appName-$appVer.jar" | |
version = appVer | |
name = appName | |
} | |
} | |
} | |
tasks { | |
withType(KotlinCompile::class).configureEach { | |
kotlinOptions { | |
jvmTarget = JavaVersion.VERSION_1_8.toString() | |
freeCompilerArgs = listOf("-progressive") | |
} | |
} | |
withType(JavaCompile::class).configureEach { | |
options.isFork = true | |
} | |
withType(Test::class).configureEach { | |
maxParallelForks = (Runtime.getRuntime().availableProcessors() / 2) | |
.takeIf { it > 0 } ?: 1 | |
useJUnitPlatform() | |
testLogging { | |
showExceptions = true | |
exceptionFormat = TestExceptionFormat.FULL | |
showStackTraces = true | |
showCauses = true | |
showStandardStreams = true | |
events = setOf( | |
TestLogEvent.PASSED, | |
TestLogEvent.SKIPPED, | |
TestLogEvent.FAILED, | |
TestLogEvent.STANDARD_OUT, | |
TestLogEvent.STANDARD_ERROR | |
) | |
} | |
reports.html.isEnabled = false | |
useJUnitPlatform() | |
} | |
wrapper { | |
gradleVersion = "6.0" | |
distributionType = Wrapper.DistributionType.ALL | |
} | |
bootJar { | |
manifest { | |
attributes("Multi-Release" to true) | |
} | |
archiveBaseName.set(appName) | |
archiveVersion.set(appVer) | |
if (project.hasProperty("archiveName")) { | |
archiveFileName.set(project.properties["archiveName"] as String) | |
} | |
} | |
register("stage") { | |
dependsOn("build", "clean") | |
} | |
register<Delete>("cleanOut") { | |
delete("out") | |
} | |
clean { | |
dependsOn("cleanOut") | |
} | |
} | |
fun gitRev() = ProcessBuilder("git", "rev-parse", "--short", "HEAD").start().let { p -> | |
p.waitFor(100, TimeUnit.MILLISECONDS) | |
p.inputStream.bufferedReader().readLine() ?: "none" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment