https://kotlinlang.org logo
#multiplatform
Title
# multiplatform
l

louiscad

06/22/2018, 5:14 PM
Hi, did anyone succeed in creating a multiplatform project using kotlin gradle scripts?
b

bnorm

06/22/2018, 8:02 PM
I've had a project working for a while: https://github.com/bnorm/PgKotlin Right now it's only JVM with a common module. I had a native subproject for a while if you look through the commit history.
❤️ 1
l

louiscad

06/22/2018, 8:24 PM
Thanks a lot! Will let you know how it went
l

lex

06/23/2018, 6:04 AM
I does it, but some extensions of frontend plugin does not work - not found error
g

gildor

06/23/2018, 5:48 PM
Do you use frontend plugin with plugins dsl or buildscript dsl?
@louiscad Also my small project with multiplatform modules and Kotlin-dsl: https://github.com/gildor/knel
l

louiscad

06/23/2018, 7:09 PM
@gildor I guess I use the plugins DSL, except for the "root project". You can see the source here: https://github.com/LouisCAD/solution.bike
g

gildor

06/24/2018, 9:46 AM
@louiscad Yes, you use plugins dsl. Do you have some particular problem? Btw, you root build.gradle.kts uses buildscript and this is not neccessary there. You can use plugins dsl instead there too My question was for @lex about missing extension
l

louiscad

06/24/2018, 9:56 AM
@gildor Your project and several others helped me get started, but I'm a bit confused about what I should do, especially since I'm not familiar with the JS ecosystem, coming from 3-4 years of Android Developement. My goal is is a bit complex: - I want to have a static files generator that can both run on the JVM (from my local machine) and from a Firebase Function (to update static files based on firestore changes and/or admin authenticated endpoint call) - I want to use Kotlin/JS for frontend logic I know I'll need several modules to achieve that, but I don't know how to make it work in the JS world. I'm digging into various resources on the web at the moment.
g

gildor

06/25/2018, 1:04 AM
I know I’ll need several modules to achieve that, but I don’t know how to make it work in the JS world
@louiscad Each Kotlin JS module compiled to one
.js
file, so easiest way just include all of them. You can use webpack to combine them if you want, but probably you can start from a few files.
l

lex

06/25/2018, 3:58 AM
@gildor sorry for late reply, I use plugins dsl
g

gildor

06/25/2018, 3:59 AM
But what kind extension is missing?
l

lex

06/25/2018, 3:59 AM
webpackBundle
Copy code
kotlinFrontend {
    sourceMaps = true
    npm {
        dependency("uuid", "^3.2.1")
    }
    webpackBundle {
        bundleName = "main"
        sourceMapEnabled = true
        contentPath = file("$buildDir/bundle")
    }
}
Copy code
Script compilation errors:

  Line 35:     webpackBundle {
               ^ Unresolved reference: webpackBundle

  Line 36:         bundleName = "main"
                   ^ Unresolved reference: bundleName

  Line 37:         sourceMapEnabled = true
                   ^ Unresolved reference: sourceMapEnabled

  Line 38:         contentPath = file("$buildDir/bundle")
                   ^ Unresolved reference: contentPath
looks like that there is no extension in generated
accessors.kt
(
gradle-kotlin-dsl-accessors
)
but
kotlinFrontend
and
npm
are there
g

gildor

06/25/2018, 4:48 AM
@lex This is because webpackBundle is configured using dynamic API
You should use
bundle
method.
l

lex

06/25/2018, 4:50 AM
can you give me a sample?
g

gildor

06/25/2018, 4:50 AM
Something like:
Copy code
kotlinFrontend {
    bundle<WebPackBundler>("webpack") {
     bundleName = "main"
   }
}
I don’t have proper example now, but it how this should work
But I agree with you, that this way to configure is not friendly to kotlin-dsl, would be good to create an issue on kotlin-frontend-plugin: https://github.com/Kotlin/kotlin-frontend-plugin/issues/new
l

lex

06/25/2018, 4:59 AM
bundle<WebPackBundler>("webpack")
does not work,
WebPackBundler
does not implement
BundleConfig
Copy code
fun <C : BundleConfig> bundle(id: String, configure: BundleConfig.() -> Unit) {
        bundleBuilders += Pair(id, configure)
    }
this does not work too
Copy code
bundle<WebPackExtension>("webpack") {
        bundleName = "main"
        sourceMapEnabled = true
        contentPath = file("$buildDir/bundle")
    }
I think
configure: BundleConfig.() -> Unit
should be
configure: C.() -> Unit
g

gildor

06/25/2018, 5:03 AM
oh, okay, you need this:
Copy code
bundle("webpack", delegateClosureOf<WebPackExtension> {
       bundleName = "main"
})
👍 1
l

lex

06/25/2018, 5:09 AM
that is work! thnx!
g

gildor

06/25/2018, 5:18 AM
as I said, it’s not kotlin friendly 😞 Will check, maybe create an issue or send PR with changes that would be easily used from Groovy and Kotlin
l

lex

06/25/2018, 5:29 AM
there is more than one problem with kts((( issue is updated
g

gildor

06/25/2018, 6:04 AM
Looks like your problem related on Kotlin2JsCompile configuration
I’m not sure that it’s correct to configure all Kotlin2JsCompile tasks with the same outputFile
l

lex

06/25/2018, 6:21 AM
I fix it, but got other errors)))
update issue
g

gildor

06/25/2018, 6:30 AM
Maybe some patsh are wrong, where is webpack.config.js?
l

lex

06/25/2018, 6:35 AM
its time to contribute)))
7 Views