123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233 |
- import org.jetbrains.kotlin.gradle.targets.js.nodejs.NodeJsRootPlugin
- import org.jetbrains.kotlin.gradle.targets.js.webpack.KotlinWebpack
- import org.jetbrains.kotlin.gradle.targets.js.webpack.KotlinWebpackConfig
- import org.springframework.boot.gradle.tasks.bundling.BootJar
- import org.springframework.boot.gradle.tasks.run.BootRun
- plugins {
- val kotlinVersion: String by System.getProperties()
- id("kotlinx-serialization") version kotlinVersion
- kotlin("multiplatform") version kotlinVersion
- id("io.spring.dependency-management") version System.getProperty("dependencyManagementPluginVersion")
- id("org.springframework.boot") version System.getProperty("springBootVersion")
- kotlin("plugin.spring") version kotlinVersion
- val kvisionVersion: String by System.getProperties()
- id("kvision") version kvisionVersion
- }
- extra["kotlin.version"] = "1.4.10"
- version = "1.0-SNAPSHOT"
- group = "me.mementomorri"
- repositories {
- mavenCentral()
- jcenter()
- mavenLocal()
- }
- // Versions
- val kotlinVersion: String by System.getProperties()
- val kvisionVersion: String by System.getProperties()
- val coroutinesVersion: String by project
- val springDataR2dbcVersion: String by project
- val r2dbcPostgresqlVersion: String by project
- val r2dbcH2Version: String by project
- val kweryVersion: String by project
- val jwtVersion: String by project
- val slugifyVersion: String by project
- val webDir = file("src/frontendMain/web")
- val mainClassName = "com.example.MainKt"
- kotlin {
- jvm("backend") {
- withJava()
- compilations.all {
- kotlinOptions {
- jvmTarget = "1.8"
- freeCompilerArgs = listOf("-Xjsr305=strict")
- }
- }
- }
- js("frontend") {
- browser {
- runTask {
- outputFileName = "main.bundle.js"
- sourceMaps = false
- devServer = KotlinWebpackConfig.DevServer(
- open = false,
- port = 3000,
- proxy = mapOf(
- "/kv/*" to "http://localhost:8080",
- "/kvws/*" to mapOf("target" to "ws://localhost:8080", "ws" to true)
- ),
- contentBase = listOf("$buildDir/processedResources/frontend/main")
- )
- }
- webpackTask {
- outputFileName = "main.bundle.js"
- }
- testTask {
- useKarma {
- useChromeHeadless()
- }
- }
- }
- binaries.executable()
- }
- sourceSets {
- val commonMain by getting {
- dependencies {
- api("io.kvision:kvision-server-spring-boot:$kvisionVersion")
- implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:$coroutinesVersion")
- }
- kotlin.srcDir("build/generated-src/common")
- }
- val commonTest by getting {
- dependencies {
- implementation(kotlin("test-common"))
- implementation(kotlin("test-annotations-common"))
- }
- }
- val backendMain by getting {
- dependencies {
- implementation(kotlin("stdlib-jdk8"))
- implementation(kotlin("reflect"))
- implementation("org.springframework.boot:spring-boot-starter")
- implementation("org.springframework.boot:spring-boot-devtools")
- implementation("org.springframework.boot:spring-boot-starter-webflux")
- implementation("org.springframework.data:spring-data-r2dbc:$springDataR2dbcVersion")
- implementation("io.r2dbc:r2dbc-postgresql:$r2dbcPostgresqlVersion")
- implementation("io.r2dbc:r2dbc-h2:$r2dbcH2Version")
- implementation("com.github.andrewoma.kwery:core:$kweryVersion")
- implementation("com.auth0:java-jwt:$jwtVersion")
- implementation("com.github.slugify:slugify:$slugifyVersion")
- }
- }
- val backendTest by getting {
- dependencies {
- implementation(kotlin("test"))
- implementation(kotlin("test-junit"))
- implementation("org.springframework.boot:spring-boot-starter-test")
- }
- }
- val frontendMain by getting {
- resources.srcDir(webDir)
- dependencies {
- implementation(npm("marked", "^0.6.3"))
- implementation("io.kvision:kvision:$kvisionVersion")
- implementation("io.kvision:kvision-redux-kotlin:$kvisionVersion")
- implementation("io.kvision:kvision-pace:$kvisionVersion")
- }
- kotlin.srcDir("build/generated-src/frontend")
- }
- val frontendTest by getting {
- dependencies {
- implementation(kotlin("test-js"))
- implementation("io.kvision:kvision-testutils:$kvisionVersion")
- }
- }
- }
- }
- fun getNodeJsBinaryExecutable(): String {
- val nodeDir = NodeJsRootPlugin.apply(project).nodeJsSetupTaskProvider.get().destination
- val isWindows = System.getProperty("os.name").toLowerCase().contains("windows")
- val nodeBinDir = if (isWindows) nodeDir else nodeDir.resolve("bin")
- val command = NodeJsRootPlugin.apply(project).nodeCommand
- val finalCommand = if (isWindows && command == "node") "node.exe" else command
- return nodeBinDir.resolve(finalCommand).absolutePath
- }
- tasks {
- create("generatePotFile", Exec::class) {
- dependsOn("compileKotlinFrontend")
- executable = getNodeJsBinaryExecutable()
- args("$buildDir/js/node_modules/gettext-extract/bin/gettext-extract")
- inputs.files(kotlin.sourceSets["frontendMain"].kotlin.files)
- outputs.file("$projectDir/src/frontendMain/resources/i18n/messages.pot")
- }
- }
- afterEvaluate {
- tasks {
- getByName("frontendProcessResources", Copy::class) {
- dependsOn("compileKotlinFrontend")
- exclude("**/*.pot")
- doLast("Convert PO to JSON") {
- destinationDir.walkTopDown().filter {
- it.isFile && it.extension == "po"
- }.forEach {
- exec {
- executable = getNodeJsBinaryExecutable()
- args(
- "$buildDir/js/node_modules/gettext.js/bin/po2json",
- it.absolutePath,
- "${it.parent}/${it.nameWithoutExtension}.json"
- )
- println("Converted ${it.name} to ${it.nameWithoutExtension}.json")
- }
- it.delete()
- }
- }
- }
- create("frontendArchive", Jar::class).apply {
- dependsOn("frontendBrowserProductionWebpack")
- group = "package"
- archiveAppendix.set("frontend")
- val distribution =
- project.tasks.getByName("frontendBrowserProductionWebpack", KotlinWebpack::class).destinationDirectory!!
- from(distribution) {
- include("*.*")
- }
- from(webDir)
- duplicatesStrategy = DuplicatesStrategy.EXCLUDE
- into("/public")
- inputs.files(distribution, webDir)
- outputs.file(archiveFile)
- manifest {
- attributes(
- mapOf(
- "Implementation-Title" to rootProject.name,
- "Implementation-Group" to rootProject.group,
- "Implementation-Version" to rootProject.version,
- "Timestamp" to System.currentTimeMillis()
- )
- )
- }
- }
- getByName("backendProcessResources", Copy::class) {
- duplicatesStrategy = DuplicatesStrategy.EXCLUDE
- }
- getByName("bootJar", BootJar::class) {
- dependsOn("frontendArchive", "backendMainClasses")
- classpath = files(
- kotlin.targets["backend"].compilations["main"].output.allOutputs +
- project.configurations["backendRuntimeClasspath"] +
- (project.tasks["frontendArchive"] as Jar).archiveFile
- )
- }
- getByName("jar", Jar::class).apply {
- dependsOn("bootJar")
- }
- getByName("bootRun", BootRun::class) {
- dependsOn("backendMainClasses")
- classpath = files(
- kotlin.targets["backend"].compilations["main"].output.allOutputs +
- project.configurations["backendRuntimeClasspath"]
- )
- }
- create("backendRun") {
- dependsOn("bootRun")
- group = "run"
- }
- getByName("compileKotlinBackend") {
- dependsOn("compileKotlinMetadata")
- }
- getByName("compileKotlinFrontend") {
- dependsOn("compileKotlinMetadata")
- }
- }
- }
|