Help with "cannot change dependencies" error

I’m trying to build a war file, in a project that uses the Kotlin multiplatform plugin. I can’t use the war plugin because it doesn’t work with the multiplatform plugin. I’m writing my own war task, and I get this error that I don’t understand:

A problem occurred configuring root project 'MyProject'.  
>  Failed to notify project evaluation listener.
    > Cannot change dependencies of configuration ':jsApi' after it has been included in dependency resolution.
    > Cannot change artifacts of configuration ':jsRuntime' after it has been included in dependency resolution.

What does that mean? My task looks like this:

task war(type: Jar) {
    dependsOn jvmMainClasses, jsMainClasses

    archiveBaseName = "myapp"
    archiveExtension = "war"

    def jsComps = kotlin.targets.js.compilations
    def jvmComps = kotlin.targets.jvm.compilations

    from(jvmComps.main.output.allOutputs.files) {
        into("WEB-INF/classes")
    }
    from(jvmComps.main.compileDependencyFiles) {
        into("WEB-INF/lib")
    }
    ...
    into('static') {  
        from(jsComps.main.output) {  // gets the .js files output by compiler
            exclude "*.scss"
        }          
        // try to get the library js files
        jsComps.main.runtimeDependencyFiles.each {  // ← problem
            from zipTree(it.absolutePath).matching {
                include '*.js'
            } 
        }
    }
}

The error shows up when I added that line about runtimeDependencyFiles. The code is trying to get the .js files out of the Kotlin libraries. They need to be there next to the JS compilation output.