Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Gradle compileKotlin includeRuntime not adding runtime to jar

I have a Kotlin Gradle project, and I would like to include Kotlin's runtime and stdlib in the jar file. I'm currently using this, but it's not including the runtime or stdlib when I build the project using the build.gradle configuration.

compileKotlin {
    kotlinOptions {
        includeRuntime = true
        noStdlib = false
    }
}

This is the Gradle code I'm using to include the runtime/stdlib in the jar, but it isn't working like I expect it to. Here's the full build.gradle file for some context: https://github.com/BenWoodworth/CrossPlatformGreeter/blob/bd1da79f36e70e3d88ed871bc35502ecc3a852fb/build.gradle#L35-L43

Kotlin's Gradle documentation seems to indicate that setting kotlinOptions.includeRuntime to true should include the Kotlin runtime in the resulting .jar.
https://kotlinlang.org/docs/reference/using-gradle.html#attributes-specific-for-kotlin

Edit: This might be related. When I run compileKotlin, I'm getting a couple of warnings related to the runtime:

:compileKotlin
w: Classpath entry points to a non-existent location: <no_path>\lib\kotlin-runtime.jar

BUILD SUCCESSFUL
like image 258
Ben Woodworth Avatar asked Feb 24 '17 01:02

Ben Woodworth


1 Answers

Here's an alternative I came up with. It'll add the Kotlin runtime and stdlib to the jar using the jar task.

jar {
    from {
        String[] include = [
            "kotlin-runtime-${version_kotlin}.jar",
            "kotlin-stdlib-${version_kotlin}.jar"
        ]

        configurations.compile
                .findAll { include.contains(it.name) }
                .collect { it.isDirectory() ? it : zipTree(it) }
    }
}
like image 170
Ben Woodworth Avatar answered Sep 28 '22 02:09

Ben Woodworth