fwcd / kotlin-language-server

Kotlin code completion, diagnostics and more for any editor/IDE using the Language Server Protocol
MIT License
1.61k stars 203 forks source link

Dependency management problems: An illegal reflective access operation has occurred #116

Open ukch opened 5 years ago

ukch commented 5 years ago

I am trying to get a development environment set up with this plugin and coc.nvim for an Android/ReactNative project. Linting seems to work, but the dependency management always fails and I get a lot of UNRESOLVED REFERENCE errors. The logs show the warning 'An illegal reflective access operation has occurred' which might be contributing to the problem. Here's the complete logs (quietmodem is the name of my project):

## Output channel: languageserver.kotlin
[Info  - 15:57:12] main      Connected to client
[Info  - 15:57:12] client    Adding workspace file:///path/to/project/android to source path
[Info  - 15:57:13] client    Adding .../quietmodem/QuietModemPackage.kt, .../quietmodem/QuietModemManager.kt, .../quietmodem/QuietModemModuleTest.kt, .../quietmodem/QuietModemModule.kt under /path/to/project/android to source path
[Info  - 15:57:13] client    Searching for dependencies in workspace root /path/to/project/android
[Info  - 15:57:13] client    Resolving dependencies for android through Gradle's CLI...
[Info  - 15:57:13] client    Creating temporary gradle file /tmp/classpath11746750311239564069.gradle
[Info  - 15:57:13] client    Found gradle at /path/to/sdkman/candidates/gradle/current/bin/gradle
[Info  - 15:58:37] client    Successfully resolved dependencies using Gradle dependencies CLI
[Info  - 15:58:39] client    Could not resolve kotlin-stdlib using Maven: null
[Info  - 15:58:39] client    Successfully resolved kotlin-stdlib using Gradle
[Info  - 15:58:39] client    Adding [/opt/android-sdk-linux/platforms/android-28/android.jar, /path/to/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-stdlib/1.3.31/11289d20fd95ae219333f3456072be9f081c30cc/kotlin-stdlib-1.3.31.jar] to class path
WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by com.intellij.openapi.util.io.FileSystemUtil$FallbackMediatorImpl (file:/path/to/KotlinLanguageServer/server/build/install/server/lib/kotlin-compiler-1.3.11.jar) to field java.io.File.fs
WARNING: Please consider reporting this to the maintainers of com.intellij.openapi.util.io.FileSystemUtil$FallbackMediatorImpl
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release

[Info  - 15:58:40] debounce0 Linting .../quietmodem/QuietModemModuleTest.kt
[Info  - 15:58:52] debounce0 Reported 18 diagnostics in QuietModemModuleTest.kt
[Info  - 15:58:52] debounce0 Ignore 4 diagnostics in QuietModemModule.kt because it's not open

Here is the contents of /path/to/project/android/build.gradle (as is common with React-native projects, the Android-specific code, including build.gradle, is in the /android directory within the project):

buildscript {
    ext {
        kotlinVersion = '1.3.31'
        androidToolsVersion = '3.2.1'
    }

    repositories {
        google()
        mavenCentral()
    }

    dependencies {
        classpath "com.android.tools.build:gradle:${project.ext.androidToolsVersion}"
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:${project.ext.kotlinVersion}"
    }
}

apply plugin: 'com.android.library'
apply plugin: 'kotlin-android'

repositories {
    google()
    jcenter()
    maven {
        // All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
        url "$rootDir/../node_modules/react-native/android"
    }
}

sourceSets {
    main.java.srcDirs = ["src/main/java"]
    test.java.srcDirs = ["src/test/java"]
}

android {
    compileSdkVersion 28

    defaultConfig {
        minSdkVersion 19
        targetSdkVersion 28
        versionCode 1
        versionName "1.0.0"
    }
    lintOptions {
        abortOnError false
    }
    testOptions {
        unitTests.all {
            useJUnitPlatform()
        }
    }
}

dependencies {
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:${project.ext.kotlinVersion}"
    implementation "com.facebook.react:react-native:+"  // From node_modules
    testImplementation "org.junit.jupiter:junit-jupiter-engine:5.4.2"
    testImplementation "io.mockk:mockk:1.9.3"
}

The test file that I am trying to lint imports io.mockk, org.junit.jupiter and com.facebook.react (all of which are specified in build.gradle as either implementation or testImplementation). Under gradle build all of these imports work, but the linter cannot seem to find these dependencies. I am not directly importing com.android but I have tested it and it seems to work without issue.

fwcd commented 5 years ago
[Info  - 15:58:39] client    Adding [/opt/android-sdk-linux/platforms/android-28/android.jar, /path/to/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-stdlib/1.3.31/11289d20fd95ae219333f3456072be9f081c30cc/kotlin-stdlib-1.3.31.jar] to class path

Apparently only android and the standard library are found by the language server, which is the reason why other imports are flagged as unresolved.

DonnieWest commented 5 years ago

Last time I tried running this setup against a React Native project I also had dependency issues. I haven't had the time to pursue getting their pretty specialized setup working 😒

Their Gradle config is pretty complex, so it's likely doing something non-typical that we're choking on. I'm personally waiting for them to calm down on some of the major changes going on and I'll be able to look into this further. Anyone else is free to look into it though in the meantime