From 95f5ffe13a874a397a22e822a00218d3f82e84eb Mon Sep 17 00:00:00 2001 From: jbion Date: Mon, 8 Jul 2019 20:39:02 +0200 Subject: Attempt at Kotlin/JS EAP build 1.3.50-eap-54 --- build.gradle.kts | 7 ++-- settings.gradle | 20 +++--------- sw-client/build.gradle.kts | 4 ++- sw-common-model/build.gradle.kts | 4 ++- sw-ui-kt/build.gradle.kts | 69 +++++++++++++++++----------------------- 5 files changed, 44 insertions(+), 60 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index 7fd3679c..6c5e98c4 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,16 +1,17 @@ plugins { - val kotlinVersion = "1.3.41" + val kotlinVersion = "1.3.50-eap-54" + kotlin("js") version kotlinVersion apply false kotlin("jvm") version kotlinVersion apply false kotlin("multiplatform") version kotlinVersion apply false kotlin("plugin.spring") version kotlinVersion apply false - id("kotlin2js") version kotlinVersion apply false - id("org.jetbrains.kotlin.frontend") version "0.0.45" apply false id("org.jlleitschuh.gradle.ktlint") version "7.1.0" apply false } subprojects { repositories { jcenter() + // keep this as long as the Gradle plugin is used in EAP version + maven(url = "https://dl.bintray.com/kotlin/kotlin-eap") } tasks.withType { diff --git a/settings.gradle b/settings.gradle index 49dfe419..6afeae6a 100644 --- a/settings.gradle +++ b/settings.gradle @@ -1,19 +1,9 @@ pluginManagement { -// repositories { -// gradlePluginPortal() -// jcenter() -// // this one is for kotlin-frontend-plugin -// maven { url "https://dl.bintray.com/kotlin/kotlin-eap" } -// } - resolutionStrategy { - eachPlugin { - if (requested.id.id == "kotlin-multiplatform" || requested.id.id == "kotlin2js") { - useModule("org.jetbrains.kotlin:kotlin-gradle-plugin:${requested.version}") - } -// if (requested.id.id == "org.jetbrains.kotlin.frontend") { -// useModule("org.jetbrains.kotlin:kotlin-frontend-plugin:${requested.version}") -// } - } + // keep this as long as the Gradle plugin is used in EAP version + repositories { + maven { url "https://dl.bintray.com/kotlin/kotlin-eap" } + gradlePluginPortal() + jcenter() } } diff --git a/sw-client/build.gradle.kts b/sw-client/build.gradle.kts index 35cebd82..07e658d0 100644 --- a/sw-client/build.gradle.kts +++ b/sw-client/build.gradle.kts @@ -7,7 +7,9 @@ val krossbowVersion = "0.3.1" kotlin { jvm() - js() + js { + browser() // necessary for local dependency from JS UI module + } sourceSets { val commonMain by getting { dependencies { diff --git a/sw-common-model/build.gradle.kts b/sw-common-model/build.gradle.kts index a9c9315b..d94559c5 100644 --- a/sw-common-model/build.gradle.kts +++ b/sw-common-model/build.gradle.kts @@ -5,7 +5,9 @@ plugins { kotlin { jvm() - js() + js { + browser() // necessary for local dependency from JS UI module + } sourceSets { val commonMain by getting { dependencies { diff --git a/sw-ui-kt/build.gradle.kts b/sw-ui-kt/build.gradle.kts index 5c84a917..a3b453ee 100644 --- a/sw-ui-kt/build.gradle.kts +++ b/sw-ui-kt/build.gradle.kts @@ -1,29 +1,40 @@ -import org.jetbrains.kotlin.gradle.frontend.util.frontendExtension -import org.jetbrains.kotlin.gradle.frontend.webpack.WebPackExtension -import org.jetbrains.kotlin.gradle.tasks.Kotlin2JsCompile +import org.jetbrains.kotlin.gradle.targets.js.webpack.KotlinWebpack plugins { - id("kotlin2js") - id("org.jetbrains.kotlin.frontend") //version "0.0.45" + kotlin("js") } repositories { - jcenter() + // repository added for kotlin-wrappers resolutions maven(url = "https://kotlin.bintray.com/kotlin-js-wrappers") } -dependencies { - implementation(kotlin("stdlib-js")) - implementation(project(":sw-common-model")) - - implementation("org.jetbrains:kotlin-react-dom:16.6.0-pre.67-kotlin-1.3.11") +kotlin { + target { + browser() + } + sourceSets { + main { + dependencies { + implementation(kotlin("stdlib-js")) + implementation(project(":sw-client")) + + implementation("org.jetbrains:kotlin-react:16.6.0-pre.78-kotlin-1.3.41") + implementation(npm("react", "16.8.3")) + implementation("org.jetbrains:kotlin-react-dom:16.6.0-pre.78-kotlin-1.3.41") + implementation(npm("react-dom", "16.8.3")) + // implementation(npm("@blueprintjs/core", "3.15.1")) + // implementation(npm("react-redux", "5.0.7")) + } + } + } } val staticFilesBuildDir = "${project.buildDir.path}/static" val staticFilesSrcDir = "$projectDir/src/main/web" tasks { - "compileKotlin2Js"(Kotlin2JsCompile::class) { + "compileKotlinJs"(KotlinJsCompile::class) { kotlinOptions.metaInfo = true kotlinOptions.outputFile = "${project.buildDir.path}/js/${project.name}.js" kotlinOptions.sourceMap = true @@ -32,15 +43,16 @@ tasks { } register("copyStatic") { - dependsOn("bundle") + dependsOn("assemble") from("${project.buildDir.path}/bundle", staticFilesSrcDir) into(staticFilesBuildDir) - val webpack = project.frontendExtension.bundles().first { it is WebPackExtension } as WebPackExtension - val bundleName = webpack.bundleName - val publicPath = webpack.publicPath + val webpack = project.tasks.withType(KotlinWebpack::class).first() + val bundleFile = webpack.outputPath.name + val publicPath = "/" // TODO get public path from webpack config + filesMatching("*.html") { - expand("bundle" to "$bundleName.bundle.js", "publicPath" to publicPath) + expand("bundle" to bundleFile, "publicPath" to publicPath) } } @@ -48,26 +60,3 @@ tasks { dependsOn("copyStatic") } } - -kotlinFrontend { - - sourceMaps = true - - webpack { - bundleName = "seven-wonders-ui" - contentPath = file(staticFilesBuildDir) - } - - npm { -// dependency("@blueprintjs/core", "3.15.1") - dependency("react", "16.8.3") - dependency("react-dom", "16.8.3") - dependency("react-redux", "5.0.7") - } -} - -fun org.jetbrains.kotlin.gradle.frontend.KotlinFrontendExtension.webpack( - configure: org.jetbrains.kotlin.gradle.frontend.webpack.WebPackExtension.() -> Unit -) { - bundle("webpack", delegateClosureOf(configure)) -} -- cgit