I set Kotlin plugin version (usually only on root ...
# gradle
g
I set Kotlin plugin version (usually only on root module or in settings.gradle) and omit version of stdlib
l
provide please sample with settings.gradle
is it .kts?
g
Can show sample on kotlin or groovy, up to you
l
show please 🙂
in kts
g
Copy code
// Actual Kotlin Version.
// Can be hardcoded or, like in this case, moved to gradle.properties
val kotlinVersion: String by settings

pluginManagement {
    repositories {
        gradlePluginPortal()
    }
    resolutionStrategy {
        eachPlugin {
            if (requested.id.id.startsWith("org.jetbrains.kotlin")) {
                useVersion(kotlinVersion)
            }
        }
    }
}
To use then just:
Copy code
plugins {
     kotlin("jvm") 
}
Instead of
jvm
can be any other Kotlin Gradle plugins, android, kapt etc
Added repositories block to pluginManagement, probably will not work without this
l
settings.gradle.kts:```val kotlin_version: String = "1.2.41" pluginManagement { repositories { gradlePluginPortal() } resolutionStrategy { eachPlugin { if (requested.id.id.startsWith("org.jetbrains.kotlin")) { useVersion(kotlin_version) } } } } include("web")```
web:
Copy code
plugins {
    `java-library`
}

apply {
    plugin("kotlin-platform-common")
}

dependencies {
    implementation(kotlin("stdlib-common"))
    testImplementation(kotlin("test-annotations-common"))
    testImplementation(kotlin("test-common"))
}
g
Hm you use
kotlin-platform-common
so you should apply it in
plugins
block
but not sure that kotlin-platform-common published to Gradle portal
but you can handle this with pluginManagement too
Yep, not published. See this issue and check workaround https://youtrack.jetbrains.com/issue/KT-20156
l
hm. ok, I'll try it later
I will be back)))
@gildor I get it work)
👍 1
settings.gradle
Copy code
rootProject.name = "kotlin-multimodule"
rootProject.buildFileName = "build.gradle.kts"

val kotlin_version: String by settings
//val kotlin_version: String = "1.2.41"

pluginManagement {
    repositories {
        gradlePluginPortal()
    }
    resolutionStrategy {
        eachPlugin {
            if (requested.id.id.startsWith("org.jetbrains.kotlin.platform")) {
                useModule("org.jetbrains.kotlin:kotlin-gradle-plugin:${kotlin_version}")
            } else if (requested.id.id.startsWith("org.jetbrains.kotlin")) {
                useVersion(kotlin_version)
            }
        }
    }
}
include("web", "web-jvm", "web-js", "back")
main build
Copy code
subprojects {
    ext["swaggerVersion"] = "2.9.0"
    ext["mapstructVersion"] = "1.2.0.Final"
    buildscript {
        repositories {
            mavenCentral()
            jcenter()
            gradlePluginPortal()
            maven("<https://jitpack.io>")
            maven("<https://dl.bintray.com/kotlin/kotlin-eap>")
        }
        dependencies {
            classpath(kotlin("gradle-plugin"))
            classpath("org.jetbrains.kotlin:kotlin-frontend-plugin:0.0.31")
            classpath("com.moowork.gradle:gradle-node-plugin:1.2.0")
            classpath("org.springframework.boot:spring-boot-gradle-plugin:2.0.2.RELEASE")
            classpath("com.github.ntrrgc:ts-generator:1.1.0")
        }
    }

    apply {
        plugin("idea")
    }

    repositories {
        mavenCentral()
        jcenter()
    }
}
:web
Copy code
plugins {
    kotlin("platform.common")
}

dependencies {
    implementation(kotlin("stdlib-common"))
    testImplementation(kotlin("test-annotations-common"))
    testImplementation(kotlin("test-common"))
}
:web-js
Copy code
import org.jetbrains.kotlin.gradle.tasks.Kotlin2JsCompile

plugins {
    kotlin("platform.js")
}

val modulePath = "$buildDir/node"

tasks {
    "copyPackageJson"(Copy::class) {
        from("build/resources/main")
        into(modulePath)
    }
    "copyJs"(Copy::class) {
        from("build/classes/kotlin/main")
        into(modulePath)
        include("*.js")
        include("*.js.map")
    }
    withType(ProcessResources::class.java) {
        expand(project.properties)
    }
    withType(Kotlin2JsCompile::class.java) {
        kotlinOptions {
            moduleKind = "commonjs"
            sourceMap = true
            sourceMapEmbedSources = "always"
            outputFile = "build/classes/kotlin/main/index.js"
        }
    }
}

dependencies {
    compile(kotlin("stdlib-js"))
    "expectedBy"(project(":web"))
    testCompile(kotlin("test-js"))
}
:web-jvm
Copy code
plugins {
    kotlin("platform.jvm")
}

dependencies {
    compile(kotlin("stdlib"))
    compile("com.google.code.findbugs:jsr305:3.0.2")
    "expectedBy"(project(":web"))
//    testCompile("junit:junit:4.12")
    testCompile(kotlin("test-junit"))
    testCompile(kotlin("test"))
}
:back
Copy code
import org.jetbrains.kotlin.gradle.dsl.Coroutines
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

plugins {
    kotlin("jvm")
    kotlin("kapt")
    kotlin("plugin.jpa")
    kotlin("plugin.spring")
    kotlin("plugin.noarg")
}
apply {
    plugin("org.springframework.boot")
    plugin("io.spring.dependency-management")
}

version = "0.1.0-SNAPSHOT"

kotlin {
    experimental.coroutines = Coroutines.ENABLE
}

tasks {
    withType(ProcessResources::class.java) {
        filesMatching("**/*.yml") {
            expand(project.properties)
        }
    }
    withType(KotlinCompile::class.java) {
        kotlinOptions.jvmTarget = "1.8"
    }
}

idea {
    module {
        // Marks the already(!) added srcDir as "generated"
        sourceDirs = sourceDirs + file("$buildDir/generated/source/kapt/main")
    }
}

noArg {
    annotation("javax.persistence.Entity")
}
val swaggerVersion: String by extra
val mapstructVersion: String by extra

dependencies {
    compile(kotlin("stdlib"))
    compile(kotlin("reflect"))
    compile("org.jetbrains.kotlinx:kotlinx-coroutines-core:0.21.2")
    compile("org.springframework.boot:spring-boot-devtools")
    compile("org.springframework.boot:spring-boot-starter-security")
    compile("org.springframework.boot:spring-boot-starter-web")
    compile("org.springframework.boot:spring-boot-starter-data-jpa")
    compile("org.springframework.data:spring-data-jpa")
    compile("org.springframework.boot:spring-boot-starter-webflux")
    compile("com.fasterxml.jackson.module:jackson-module-kotlin")
    compile("com.fasterxml.jackson.dataformat:jackson-dataformat-xml")
    compile("io.springfox:springfox-swagger2:$swaggerVersion")
    compile("io.springfox:springfox-bean-validators:$swaggerVersion")
    compile("io.springfox.ui:springfox-swagger-ui-rfc6570:1.0.0")
    compile("io.github.microutils:kotlin-logging:1.5.0")
    compile("org.kotlinprimavera:security:0.5")
    compile("org.flywaydb:flyway-core")
    compile("com.zaxxer:HikariCP")
    compile(project (":web-jvm"))
    compile("org.mapstruct:mapstruct-jdk8:$mapstructVersion")
    kapt("org.mapstruct:mapstruct-processor:$mapstructVersion")
    runtime("com.h2database:h2")
    testCompile("org.springframework.boot:spring-boot-starter-test")
}