I'm developing Kotlin/JS Project and I have create...
# javascript
f
I'm developing Kotlin/JS Project and I have created new sourceSets but by default makes the type = Multiplataform. How can change KotlinPlatformType in gradle? Gradle code:
Copy code
val backend by creating{}
val webapp  by creating{}
i
Do you apply
org.jetbrains.kotlin.multiplatform
plugin?
f
@Ilya Goncharov [JB] not, I applied Kotlin/JS plugin. Gradle Code:
Copy code
plugins {
    kotlin("js") version "1.4-M1"
}
repositories {
    maven("<https://dl.bintray.com/kotlin/kotlin-eap>")
    jcenter()
    mavenCentral()
}

kotlin {
  sourceSets {
        val commonMain by creating {
          dependencies {
                implementation(kotlin("stdlib-js"))
            }
        }
		
		val backend by creating{
            group = "org.example"
            version = "1.0.0"
            target {
                nodejs()
                produceExecutable()
            }
			
            dependencies {
                implementation(kotlin("stdlib-js"))
            }
        }

        val webapp by creating{
            group = "org.example"
            version = "1.0.0"

            target {
                browser()
                produceExecutable()
            }
            dependencies {
                implementation(kotlin("stdlib-js"))
                implementation("org.jetbrains.kotlinx:kotlinx-html-js:$html_version")
                implementation("io.socket:socket.io-client:1.0.0"){
                    exclude("or.json","json") // excluding org.json which is provided by Android
                }
            }
	    }
    }
}
i
Thank you, I see Seems that some problems with IDEA import from Kotlin side. Seems that it should not affect build. Do you faced with some red code or build problem? Btw
Copy code
target {
   ...
}
is code, which configure per module, it is for configure full JS target, not only one source set. Honestly, for now we don’t fully support multiple source sets. For your case, I think you can use multi module Gradle build.
Copy code
- root
 - common Kotlin/JS module
 - backend Kotlin/JS module
 - webapp Kotlin/JS module
And use dependencies like this
backend
Copy code
dependencies {
     implementation(project("common"))
}
f
@Ilya Goncharov [JB], I found this project structure in a Jetbrains Kotlin/MPP sample project. I liked because the code was in the same folder. (src\<target>\kotlin).
Do you faced with some red code or build problem?
when I run build task I have 2 problems: 1 - ':compileKotlinJs' task going to search kotlin classes to 'main' no other sourceSets(backed etc...). 2- :browserProductionWebpack task not found other JS libraries. I think than having multiples sourceSets gives me this problems. With Kotlin MPP, Can i configure multiples JS Projects by sourceSets? Jetbrains planning to increase support for multiple sourceSets?
i
Jetbrains planning to increase support for multiple sourceSets?
Yes, I think you need so called HMPP in 1.4 release, but for now it is in experimenting mode for mobile multiplatform
With Kotlin MPP, Can i configure multiples JS Projects by sourceSets?
You need to declare tasks for your source sets manually, so it will be very inconvenient. I am making refactorings time by time to make it easier to work with multiple source sets. But for now it is not this time unfortunately. ANd in fact tasks will be added for
main
and
test
source sets. Could you please link me to this Kotlin/MPP sample project?
f
@Ilya Goncharov [JB], Do you have more info about Hierarchical Multiplatform Projects for follow it? Jetbrains Kotlin MPP sample: https://github.com/kotlin-hands-on/jvm-js-fullstack/blob/master/build.gradle.kts Official guide Kotlin MPP: https://github.com/kotlin-hands-on/jvm-js-fullstack/blob/master/build.gradle.kts
i
Thank you! In sample, you can get predefined source sets
commonMain
and
jsMain
to declare dependencies (And you send one link twice, but I understand, what you mean) And with these source sets everything will work, but
commonMain
is place for common non platfrom-specific code. About HMPP there will be articles, but for now I am not sure :(
f
@Ilya Goncharov [JB], Jetbrains plan to replace multi-module projects by HMPP in kotlin?
i
No, they can live together
f
@Ilya Goncharov [JB], Advantages and disadvantages or limitations? I suppose that in the future there will be some article that explains it.