google / google/compile-testing

"NoSuchMethodError" for "javac" operations when used alongside "kotlin-compiler" dependency

Open
#158 2 comments 0 reactions 0 assignees View on GitHub
P3
Dominant language
Java
Stars
722
Forks
129
Avg merge
11m
Merged PRs (30d)
4

Description

There seems to be some sort of incompatibility issue between this library and "kotlin-compiler". If I try to access operations on `Compiler` (accessed via `javac()`) such as `withProcessors` or `withOptions`, I get `NoSuchMethodError` exceptions.

This can be minimally reproduced by creating a Gradle project with a `build.gradle.kts` file in the root directory:

```gradle
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

plugins {
kotlin("jvm") version "1.3.0"
}

repositories {
mavenCentral()
}

dependencies {
implementation(kotlin("stdlib-jdk8"))
implementation("com.google.testing.compile:compile-testing:0.15")

// Problematic import when combined with compile-testing
implementation("org.jetbrains.kotlin:kotlin-compiler:1.2.51")
}

tasks.withType {
kotlinOptions.jvmTarget = "1.8"
}
```

And then creating a file `src/main/kotlin/experiment.kt` under the project root directory:

```kotlin
import com.google.testing.compile.Compiler.javac

fun main(args: Array) {
javac().withProcessors()
}
```

Running this gives me:

```
Exception in thread "main" java.lang.NoSuchMethodError: com.google.common.collect.ImmutableList.copyOf([Ljava/lang/Object;)Lcom/google/common/collect/ImmutableList;
at com.google.testing.compile.Compiler.withProcessors(Compiler.java:71)
at experiment.ExperimentKt.main(experiment.kt:6)
```

Initially raised at cretz/kastree#4.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.