如何添加gradle任务以编译其他SourceSet

时间:2020-02-05 21:57:28

标签: javascript gradle kotlin dsl source-sets

我有一个使用的KotlinJS项目

plugins {
  kotlin("js")
}

Kotlin-compiler-plugin在执行任务构建时生成新的.kt文件(现在位于文件夹$buildDir/src/main/generated中)。 不幸的是,我不得不再次调用build来编译生成的源 因此,我想添加一个通过

编译生成的源的任务
tasks.register("compileGenerated", org.jetbrains.kotlin.gradle.tasks.Kotlin2JsCompile::class) {
    sourceSets {
        create("generated") {
            kotlin.srcDir("${buildDir}/src/generated/kotlin/")
            dependsOn(sourceSets.getByName("main"))
        }
     }
}

在每次构建结束时我都会使用finalizedBy

调用该任务

尝试一下,我只会收到以下消息:

> Could not create task ':examples:nestedmodel:model:compileGenerated'.
> Project#afterEvaluate(Action) on project ':example' cannot be executed in the current context.

说实话,我不知道为什么...

0 个答案:

没有答案
相关问题