0

I have a kotlin (test) class with the following import:

import com.sun.tools.attach.VirtualMachine

In IDEA I have added the tools.jar to the SDK classpath. It runs fine in IDEA but I get errors when running from gradle in compileTestKotlin:

Unresolved reference: tools
Unresolved reference: VirtualMachine

Caused by: org.gradle.api.GradleException: Compilation error. See log for more details
    at org.jetbrains.kotlin.gradle.tasks.TasksUtilsKt.throwGradleExceptionIfError(tasksUtils.kt:8)
    at org.jetbrains.kotlin.gradle.tasks.KotlinCompile.processCompilerExitCode(Tasks.kt:415)
    at org.jetbrains.kotlin.gradle.tasks.KotlinCompile.callCompiler$kotlin_gradle_plugin(Tasks.kt:389)
    at org.jetbrains.kotlin.gradle.tasks.KotlinCompile.callCompiler$kotlin_gradle_plugin(Tasks.kt:251)
    at org.jetbrains.kotlin.gradle.tasks.AbstractKotlinCompile.execute(Tasks.kt:215)

How do I get the gradle build to use the tools.jar?

The key parts of build.gradle looks like this:

buildscript {
    ext.kotlin_version = '1.2.21'

    repositories {
        jcenter()
    }

    dependencies {
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
    }
}

apply plugin: 'kotlin'
apply plugin: 'idea'

dependencies {
    compile "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
    testCompile "org.jetbrains.kotlin:kotlin-test:$kotlin_version"
}

tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).all {
    kotlinOptions {
        languageVersion = "1.1"
        apiVersion = "1.1"
        jvmTarget = "1.8"
        javaParameters = true   // Useful for reflection.
    }
}
guenhter
  • 11,255
  • 3
  • 35
  • 66
opticyclic
  • 7,412
  • 12
  • 81
  • 155
  • Try running the gradle command with the `--scan` option and show us the detailed stacktrace, please. – blubb Mar 09 '18 at 06:51
  • You should not add an SDK to the classpath, but use Gradle to include the dependency. IDEA will automatically inspect the build script and add all relevant dependencies to the classpath automatically. So include your dependencies in the build file – s1m0nw1 Mar 09 '18 at 07:00
  • How can you add tools.jar as a dependency? – opticyclic Apr 02 '18 at 15:19

0 Answers0