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

Ray Rahke

03/10/2024, 5:20 AM
I have a kotlin-compiling-to-js application using multiplatform. I don't want the folder structure to be
src/jsMain/Kotlin
How can I change it? Here are the contents of my gradle file
Copy code
plugins {
    kotlin("multiplatform") version "1.9.22"
}

group = "org.example"
version = "1.0-SNAPSHOT"

repositories {
    mavenCentral()
}

kotlin {
    jvmToolchain(21)
    sourceSets {
        commonTest {
            dependencies {
                implementation(kotlin("test"))
            }
        }
    }
    js {
        browser {
            commonWebpackConfig {
                outputFileName = "main.js"
            }
        }
        binaries.executable()

    }
}
e

ephemient

03/10/2024, 5:33 AM
you should really re-order that so that the targets are specified before the source sets are set up. doesn't matter for common since it's always there, but for anything else it does matter
in any case the api mirrors typical gradle sourcesets
Copy code
kotlin {
    sourceSets {
        val jsMain by getting {
            kotlin.srcDir("additional/kotlin/sources")
            resources.srcDir("additional/resources")
but why??
r

Ray Rahke

03/10/2024, 6:00 AM
but why??
Because this is for teaching children who don't need to know about these distinctions that will just function as visual noise that scares and confuses them
I just want
src/
e

ephemient

03/10/2024, 6:00 AM
you need separate folders for resources and kotlin sources at least
and you should have tests too
and at that point you're basically at the same place
r

Ray Rahke

03/10/2024, 8:06 AM
Is it possible to have src/ main.kt resources/ ... test/ ...
e

ephemient

03/10/2024, 8:11 AM
just
srcDirs
like above. but I don't think breaking the norms is worth it. every language has its expected structure, even simple scripting languages once you get beyond single-file projects.
r

Ray Rahke

03/10/2024, 8:12 AM
these are 8 year olds lol
internalizing industry standards for a particular language is not a large priority
I only chose Kotlin for them because it has the best syntax
they will forget everything in 3 years anyway, hah
e

ephemient

03/10/2024, 8:13 AM
8 year olds can click a couple things just fine. I had classes way back in the day with LOGO
r

Ray Rahke

03/10/2024, 8:13 AM
yeah I know, but for little kids who aren't super familiar with computers, the more visual noise and boiler plate the more disoriented they feel
instead, if they are launched into an IDE and just see 1 folder src, with 1 file main.kt, with 1 function main() which prints hello world, it all just clicks as super intuitive for them
and they feel like they understand all the moving pieces
some of my students would be fine with memorizing "go into src/ then jsMain then kotlin/ then main.kt"
but some of my other students, in our current python class where we literally only have src/main.py, still struggle with knowing where to click constantlyl
a huge pain during our lessons.
watching them go into a disoriented panic mode where they look in all directions and start opening tons of stuff
kotlin { sourceSets { val jsMain by getting { kotlin.srcDir("additional/kotlin/sources") resources.srcDir("additional/resources") what is "additional" here?
Copy code
kotlin {
    sourceSets {
        val jsMain by getting {
            kotlin.srcDir("src/*")
            js.srcDir("src/jsstuff/*")
            resources.srcDir("resources/*")
            test.srcDir("test/*")
something like this?
src/ jsstuff/ canvassetup.kt main.kt resources/ index.html test/ ...
is what I have in mind.
2 Views