缺少将kotlin编译为javascript的kotlin.js.map文件以用于gradle

缺少将kotlin编译为javascript的kotlin.js.map文件以用于gradle,gradle,kotlin,Gradle,Kotlin,我将Kotlin编译为JS,它运行得很好,但浏览器总是显示错误: 在控制台日志中 加载资源失败:服务器响应状态为404(未找到) 这是我的build.gradle文件: group 'org.example' version '1.0-SNAPSHOT' buildscript { ext.kotlin_version = '1.3.50' repositories { mavenCentral() } dependencies {

我将Kotlin编译为JS,它运行得很好,但浏览器总是显示错误:

在控制台日志中

加载资源失败:服务器响应状态为404(未找到)

这是我的build.gradle文件:

group 'org.example'
version '1.0-SNAPSHOT'

buildscript {
    ext.kotlin_version = '1.3.50'
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
    }
}
apply plugin: 'kotlin2js'

repositories {
    mavenCentral()
}

dependencies {
    compile "org.jetbrains.kotlin:kotlin-stdlib-js:$kotlin_version"
}

task assembleWeb(type: Sync) {
    configurations.compile.each { File file ->
        from(zipTree(file.absolutePath), {
            includeEmptyDirs = false
            include { fileTreeElement ->
                def path = fileTreeElement.path
                path.endsWith(".js") && (path.startsWith("META-INF/resources/") ||
                        !path.startsWith("META-INF/"))
            }
        })
    }
    compileKotlin2Js {
        kotlinOptions.outputFile = "${projectDir}/web/output.js"
        kotlinOptions.moduleKind = "plain"
        kotlinOptions.sourceMap = true
        kotlinOptions.sourceMapEmbedSources = "always"


    }

    from compileKotlin2Js.destinationDir
    into "${projectDir}/web/js"
    dependsOn classes
}

task copyHTMLFolder(type: Copy) {
    dependsOn assembleWeb
    from file("src/html/")
    into file("${projectDir}/web/")
}

task openUrlInBrowser {
    dependsOn copyHTMLFolder
    doLast {
        java.awt.Desktop.desktop.browse "http://localhost:63342/engineEmi/web/index.html".toURI()
    }
}

assemble.dependsOn assembleWeb

sourceSets {
    main.kotlin.srcDirs += 'src/'
    main.java.srcDirs += 'src/'
}
如何让gradle生成kotlin.ja.map文件


亲切地问候我。该文件已创建,但未从META-INF复制,因为只有.js文件被复制

下面是assembleWeb任务的工作实现(请参阅带有path.endsWith的条件

task assembleWeb(type: Sync) {
    configurations.compile.each { File file ->
        from(zipTree(file.absolutePath), {
            includeEmptyDirs = false
            include { fileTreeElement ->
                def path = fileTreeElement.path
                (path.endsWith(".js") || path.endsWith(".map")) && (path.startsWith("META-INF/resources/") || !path.startsWith("META-INF/"))
            }
        })
    }
    compileKotlin2Js {
        kotlinOptions.outputFile = "${projectDir}/web/output.js"
        kotlinOptions.moduleKind = "plain"
        kotlinOptions.sourceMap = true
        kotlinOptions.sourceMapEmbedSources = "always"


    }

    from compileKotlin2Js.destinationDir
    into "${projectDir}/web/js"
    dependsOn classes
}