Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Kotlin gradle plugin - how to use custom output directory?

Tags:

gradle

kotlin

In seems that Kotlin Gradle plugin ignores the specified compilation output directory:

sourceSets {
    main {
        kotlin {
            srcDirs 'source/kotlin'
            outputDir = file('work/program')
        }
    }
}

The compiler output goes to 'build/classes/kotlin/main' directory instead of 'work/program'. But outputDir specified in the same way works as expected in Java Gradle projects.

Is there a way to use custom compiler output directory with Kotlin Gradle plugin? (versions: Kotlin 1.2.31, Gradle 4.6)

Update: I submitted bug report about this: https://youtrack.jetbrains.com/issue/KT-23807

like image 546
Dimitar II Avatar asked Nov 07 '22 08:11

Dimitar II


1 Answers

There is workaround, posted by other user in the Kotlin issue tracker:

tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).all {
    destinationDir = new File(buildDir, "work/program")
}

(add this fragment in your 'build.gradle' file)

like image 56
Dimitar II Avatar answered Nov 14 '22 20:11

Dimitar II