raniejade/spek-idea-plugin

java.lang.NoSuchMethodError for internal method/functions

Closed this issue · 5 comments

When I define a function as internal and run the test on the Intellij, I got the error below. But the command ./gradlew clean test works like a charm.

objc[17110]: Class JavaLaunchHelper is implemented in both /Library/Java/JavaVirtualMachines/jdk1.8.0_131.jdk/Contents/Home/bin/java (0x10f1be4c0) and /Library/Java/JavaVirtualMachines/jdk1.8.0_131.jdk/Contents/Home/jre/lib/libinstrument.dylib (0x10f2864e0). One of the two will be used. Which one is undefined.
java.lang.NoSuchMethodError: spiders.Stm.getNumberAndStatus(Ljava/lang/String;)Lkotlin/Pair;
	at spiders.StmSpec$1$1$1.invoke(StmSpec.kt:15)
	at spiders.StmSpec$1$1$1.invoke(StmSpec.kt:10)
	at org.jetbrains.spek.engine.SpekTestEngine$Collector$action$action$1.invoke(SpekTestEngine.kt:175)
	at org.jetbrains.spek.engine.SpekTestEngine$Collector$action$action$1.invoke(SpekTestEngine.kt:133)
	at org.jetbrains.spek.engine.Scope$Action.execute(Scope.kt:55)
	at org.jetbrains.spek.engine.Scope$Action.execute(Scope.kt:38)
	at org.junit.platform.engine.support.hierarchical.Node.execute(Node.java:94)
	at org.junit.platform.engine.support.hierarchical.HierarchicalTestExecutor.lambda$execute$1(HierarchicalTestExecutor.java:81)
	at org.junit.platform.engine.support.hierarchical.SingleTestExecutor.executeSafely(SingleTestExecutor.java:66)
	at org.junit.platform.engine.support.hierarchical.HierarchicalTestExecutor.execute(HierarchicalTestExecutor.java:76)
	at org.junit.platform.engine.support.hierarchical.HierarchicalTestExecutor.lambda$execute$1(HierarchicalTestExecutor.java:91)
	at org.junit.platform.engine.support.hierarchical.SingleTestExecutor.executeSafely(SingleTestExecutor.java:66)
	at org.junit.platform.engine.support.hierarchical.HierarchicalTestExecutor.execute(HierarchicalTestExecutor.java:76)
	at org.junit.platform.engine.support.hierarchical.HierarchicalTestExecutor.lambda$execute$1(HierarchicalTestExecutor.java:91)
	at org.junit.platform.engine.support.hierarchical.SingleTestExecutor.executeSafely(SingleTestExecutor.java:66)
	at org.junit.platform.engine.support.hierarchical.HierarchicalTestExecutor.execute(HierarchicalTestExecutor.java:76)
	at org.junit.platform.engine.support.hierarchical.HierarchicalTestExecutor.lambda$execute$1(HierarchicalTestExecutor.java:91)
	at org.junit.platform.engine.support.hierarchical.SingleTestExecutor.executeSafely(SingleTestExecutor.java:66)
	at org.junit.platform.engine.support.hierarchical.HierarchicalTestExecutor.execute(HierarchicalTestExecutor.java:76)
	at org.junit.platform.engine.support.hierarchical.HierarchicalTestExecutor.execute(HierarchicalTestExecutor.java:51)
	at org.junit.platform.engine.support.hierarchical.HierarchicalTestEngine.execute(HierarchicalTestEngine.java:43)
	at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:137)
	at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:87)
	at org.junit.platform.launcher.Launcher.execute(Launcher.java:93)
	at org.jetbrains.spek.tooling.runner.junit.JUnitPlatformSpekRunner.run(JUnitPlatformSpekRunner.kt:107)
	at org.jetbrains.spek.tooling.MainKt.main(Main.kt:5

build.gradle

group 'br.com.jusbrasil.crawler'
version '1.0-SNAPSHOT'

buildscript {
    ext.kotlinVersion = '1.1.3-2'
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion"
        classpath 'org.junit.platform:junit-platform-gradle-plugin:1.0.0-M4'
    }
}

apply plugin: 'kotlin'
apply plugin: 'org.junit.platform.gradle.plugin'

junitPlatform {
    filters {
        engines {
            include 'spek'
        }
    }
}

repositories {
    mavenCentral()
    maven { url "http://dl.bintray.com/jetbrains/spek" }
}

dependencies {
    compile "org.jetbrains.kotlin:kotlin-stdlib-jre8:$kotlinVersion"
    compile "org.jetbrains.kotlin:kotlin-reflect:$kotlinVersion"
    compile 'org.jsoup:jsoup:1.10.3'
    compile 'org.apache.httpcomponents:fluent-hc:4.5.3'

    // TODO: remove when upgrade kotlin to version 1.2
    compile "uy.kohesive.klutter:klutter-core:2.2.+"

    // test
    testCompile 'org.jetbrains.spek:spek-api:1.1.2'
    testCompile "org.jetbrains.kotlin:kotlin-test:$kotlinVersion"
    testRuntime 'org.jetbrains.spek:spek-junit-platform-engine:1.1.2'

    // Only needed to run tests in an (IntelliJ) IDE(A) that bundles an older version
    testRuntime "org.junit.platform:junit-platform-launcher:1.0.0-M4"
}

compileKotlin {
    kotlinOptions.jvmTarget = "1.8"
}

compileTestKotlin {
    kotlinOptions.jvmTarget = "1.8"
}

What version of IDEA are you using? Also can you try:

testCompile('org.jetbrains.spek:spek-api:1.1.2') {
     exclude group: 'org.jetbrains.kotlin'
}

testCompile('org.jetbrains.spek:spek-junit-platform-engine:1.1.2') {
     exclude group: 'org.jetbrains.kotlin'
}

Thanks, @raniejade. Now it's working.

I have no idea what's happened, but after closing the IDEA and reopen, everything is working well.

This is really needed? http://spekframework.org/docs/latest/#_using_later_versions_of_kotlin

The IDEA version.

IntelliJ IDEA 2017.2
Build #IU-172.3317.76, built on July 15, 2017
Licensed to Robson Peixoto
Subscription is active until December 2, 2017
JRE: 1.8.0_152-release-915-b5 x86_64
JVM: OpenJDK 64-Bit Server VM by JetBrains s.r.o
Mac OS X 10.12.6

Good to know. Yes if you want to use the latest version of kotlin, spek's dependency will pull in an older version of kotlin.

@raniejade I think it's not necessary.

The gradle/maven should respect the priorities. The output of the command ./gradlew dependencies

testRuntimeClasspath - Runtime classpath of source set 'test'.
+--- org.jetbrains.kotlin:kotlin-stdlib-jre8:1.1.3-2
|    +--- org.jetbrains.kotlin:kotlin-stdlib:1.1.3-2
|    |    \--- org.jetbrains:annotations:13.0
|    \--- org.jetbrains.kotlin:kotlin-stdlib-jre7:1.1.3-2
|         \--- org.jetbrains.kotlin:kotlin-stdlib:1.1.3-2 (*)
+--- org.jetbrains.kotlin:kotlin-reflect:1.1.3-2
|    \--- org.jetbrains.kotlin:kotlin-stdlib:1.1.3-2 (*)
+--- org.jsoup:jsoup:1.10.3
+--- org.apache.httpcomponents:fluent-hc:4.5.3
|    +--- org.apache.httpcomponents:httpclient:4.5.3
|    |    +--- org.apache.httpcomponents:httpcore:4.4.6
|    |    +--- commons-logging:commons-logging:1.2
|    |    \--- commons-codec:commons-codec:1.9
|    \--- commons-logging:commons-logging:1.2
+--- uy.kohesive.klutter:klutter-core:2.2.+ -> 2.2.0
|    +--- org.jetbrains.kotlin:kotlin-stdlib:1.1.2 -> 1.1.3-2 (*)
|    \--- org.jetbrains.kotlin:kotlin-stdlib-jre8:1.1.2 -> 1.1.3-2 (*)
+--- org.jetbrains.kotlin:kotlin-test:1.1.3-2
|    \--- org.jetbrains.kotlin:kotlin-stdlib:1.1.3-2 (*)
+--- org.jetbrains.spek:spek-api:1.1.2
|    +--- org.jetbrains.kotlin:kotlin-stdlib:1.0.6 -> 1.1.3-2 (*)
|    \--- org.jetbrains.kotlin:kotlin-reflect:1.0.6 -> 1.1.3-2 (*)
+--- org.jetbrains.spek:spek-junit-platform-engine:1.1.2
|    +--- org.jetbrains.kotlin:kotlin-stdlib:1.0.6 -> 1.1.3-2 (*)
|    +--- org.jetbrains.kotlin:kotlin-reflect:1.0.6 -> 1.1.3-2 (*)
|    \--- org.jetbrains.spek:spek-api:1.1.2 (*)
\--- org.junit.platform:junit-platform-launcher:1.0.0-M4
     \--- org.junit.platform:junit-platform-engine:1.0.0-M4
          +--- org.junit.platform:junit-platform-commons:1.0.0-M4
          \--- org.opentest4j:opentest4j:1.0.0-M2

Yeah that's good as long as you also pull the correct version of kotlin-reflect, it's not backward/forward compatible. In your case you specified the dependency for kotlin-reflect:1.1.3-2, that's why it's working. Most of the time people don't need kotlin-reflect so they just include the latest version of kotlin-stdlib. Since spek pulls in an older version it's going to fail at runtime.