Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

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

Open
TAGC opened this issue Oct 31, 2018 · 2 comments
Labels

Comments

@TAGC
Copy link

TAGC commented Oct 31, 2018

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:

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<KotlinCompile> {
    kotlinOptions.jvmTarget = "1.8"
}

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

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

fun main(args: Array<String>) {
    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.

@TAGC
Copy link
Author

TAGC commented Oct 31, 2018

Here's a build scan which might be useful (I added the "application" plugin to the Gradle build script to let me run the main function).

@tbroyer
Copy link

tbroyer commented Oct 31, 2018

org.jetbrains.kotlin:kotlin-compiler:1.2.51 bundles its dependencies (including Guava) into the JAR, shadowing the "real" Guava; and it probably uses a version of Guava that didn't have that method. It will thus break anything that also depends on Guava (or any other bundled dependency: JNA, JavaSlang, GNU Trove, JANSI, JDOM, etc.)

Either kotlin-compiler is not meant to be used as a dependency, or they have a packaging issue.

@raghsriniv raghsriniv added the P3 label Jun 26, 2019
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants