Hi, did anyone succeed in creating a multiplatform...
# multiplatform
l
Hi, did anyone succeed in creating a multiplatform project using kotlin gradle scripts?
b
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
Thanks a lot! Will let you know how it went
l
I does it, but some extensions of frontend plugin does not work - not found error
g
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
@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
@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
@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
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
@gildor sorry for late reply, I use plugins dsl
g
But what kind extension is missing?
l
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
@lex This is because webpackBundle is configured using dynamic API
You should use
bundle
method.
l
can you give me a sample?
g
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
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
oh, okay, you need this:
Copy code
bundle("webpack", delegateClosureOf<WebPackExtension> {
       bundleName = "main"
})
👍 1
l
that is work! thnx!
g
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
there is more than one problem with kts((( issue is updated
g
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
I fix it, but got other errors)))
update issue
g
Maybe some patsh are wrong, where is webpack.config.js?
l
its time to contribute)))