fwcd / fwcd/kotlin-language-server

Dependency management problems: An illegal reflective access operation has occurred

Open
#116 2 comments 0 reactions 0 assignees View on GitHub
bug dependency resolution
Dominant language
Kotlin
Stars
2k
Forks
252
PR merge metrics
No merged PRs in 30d

Description

I am trying to get a development environment set up with this plugin and [coc.nvim](https://github.com/neoclide/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):
```gradle
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.

Contributor guide

No contributing guide indexed for this repository

Research direction

Start with the dependency-resolution output and the Android build.gradle shown in the report, then reproduce the KotlinLanguageServer setup with the listed React Native project and test imports. Compare Gradle's resolved dependencies with the language server's class path; done means the listed imports no longer produce unresolved-reference diagnostics during linting.

Written by the indexing model from the issue text.

Assessment

Tech stack
android, kotlin, react-native
Domain
build-system, devtools
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.