Skip to content

Use new Kotlin/JS plugin #1983

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
May 19, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ configure(subprojects.findAll { it.name != coreModule && it.name != rootModule }
}

// Redefine source sets because we are not using 'kotlin/main/fqn' folder convention
configure(subprojects.findAll { !sourceless.contains(it.name) && it.name != "benchmarks" && it.name != coreModule }) {
configure(subprojects.findAll { !sourceless.contains(it.name) && it.name != "benchmarks" && it.name != 'example-frontend-js' && it.name != coreModule }) {
sourceSets {
main.kotlin.srcDirs = ['src']
test.kotlin.srcDirs = ['test']
Expand Down
13 changes: 10 additions & 3 deletions gradle/compile-js.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,29 @@

// Platform-specific configuration to compile JS modules

apply plugin: 'kotlin2js'
apply plugin: 'org.jetbrains.kotlin.js'

kotlin.sourceSets {
main.kotlin.srcDirs = ['src']
test.kotlin.srcDirs = ['test']
main.resources.srcDirs = ['resources']
test.resources.srcDirs = ['test-resources']
}

dependencies {
compile "org.jetbrains.kotlin:kotlin-stdlib-js:$kotlin_version"
testCompile "org.jetbrains.kotlin:kotlin-test-js:$kotlin_version"
}

tasks.withType(compileKotlin2Js.getClass()) {
tasks.withType(compileKotlinJs.getClass()) {
kotlinOptions {
moduleKind = "umd"
sourceMap = true
metaInfo = true
}
}

compileKotlin2Js {
compileKotlinJs {
kotlinOptions {
// drop -js suffix from outputFile
def baseName = project.name - "-js"
Expand Down
31 changes: 3 additions & 28 deletions js/example-frontend-js/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,36 +5,19 @@
apply plugin: 'kotlin-dce-js'
apply from: rootProject.file('gradle/node-js.gradle')

// Workaround resolving new Gradle metadata with kotlin2js
// TODO: Remove once KT-37188 is fixed
try {
def jsCompilerType = Class.forName("org.jetbrains.kotlin.gradle.targets.js.JsCompilerType")
def jsCompilerAttr = Attribute.of("org.jetbrains.kotlin.js.compiler", jsCompilerType)
project.dependencies.attributesSchema.attribute(jsCompilerAttr)
configurations {
matching {
it.name.endsWith("Classpath")
}.forEach {
it.attributes.attribute(jsCompilerAttr, jsCompilerType.legacy)
}
}
} catch (java.lang.ClassNotFoundException e) {
// org.jetbrains.kotlin.gradle.targets.js.JsCompilerType is missing in 1.3.x
// But 1.3.x doesn't generate Gradle metadata, so this workaround is not needed
}

dependencies {
compile "org.jetbrains.kotlinx:kotlinx-html-js:$html_version"
}

compileKotlin2Js {
compileKotlinJs {
kotlinOptions {
main = "call"
}
}

task bundle(type: NpmTask, dependsOn: [npmInstall, runDceKotlinJs]) {
task bundle(type: NpmTask, dependsOn: [npmInstall, build]) {
inputs.files(fileTree("$buildDir/kotlin-js-min/main"))
inputs.files(fileTree("$buildDir/kotlin-js-min/legacy/main"))
inputs.files(fileTree(file("src/main/web")))
inputs.file("npm/webpack.config.js")
outputs.dir("$buildDir/dist")
Expand All @@ -44,11 +27,3 @@ task bundle(type: NpmTask, dependsOn: [npmInstall, runDceKotlinJs]) {
task start(type: NpmTask, dependsOn: bundle) {
args = ["run", "start"]
}

// we have not tests but kotlin-dce-js still tries to work with them and crashed.
// todo: Remove when KT-22028 is fixed
afterEvaluate {
if (tasks.findByName('unpackDependenciesTestKotlinJs')) {
tasks.unpackDependenciesTestKotlinJs.enabled = false
}
}
1 change: 1 addition & 0 deletions js/example-frontend-js/npm/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ module.exports = {
resolve: {
modules: [
path.resolve(__dirname, "kotlin-js-min/main"),
path.resolve(__dirname, "kotlin-js-min/legacy/main"),
path.resolve(__dirname, "../src/main/web/")
]
},
Expand Down